Update run-tests.sh
[pin4sha_cgi.git] / scripts / run-tests.sh
blobe7d095a73aac6b326fe79a09b846bb423f23711c
1 #!/bin/sh
3 # Copyright (c) 2015 Marcus Rohrmoser http://mro.name/me. All rights reserved.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # Check preliminaries
20 curl --version >/dev/null || { echo "I need curl." && exit 101 ; }
21 xmllint --version 2> /dev/null || { echo "I need xmllint." && exit 102 ; }
22 ruby --version > /dev/null || { echo "I need xmllint." && exit 103 ; }
24 cd "$(dirname "$0")/.."
25 CWD=$(pwd)
27 # terminal colors (require bash)
28 # http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
29 # http://wiki.bash-hackers.org/scripting/terminalcodes
30 FGC_NONE="\033[0m"
31 FGC_GRAY="\033[1;30m"
32 FGC_RED="\033[1;31m"
33 FGC_GREEN="\033[1;32m"
34 FGC_YELLOW="\033[1;33m"
35 FGC_BLUE="\033[1;34m"
36 FGC_PURPLE="\033[1;35m"
37 FGC_CYAN="\033[1;36m"
38 FGC_WHITE="\033[1;37m"
39 BGC_GRAY="\033[7;30m"
40 BGC_RED="\033[7;31m"
41 BGC_GREEN="\033[7;32m"
42 BGC_YELLOW="\033[7;33m"
43 BGC_BLUE="\033[7;34m"
44 BGC_PURPLE="\033[7;35m"
45 BGC_CYAN="\033[7;36m"
46 BGC_WHITE="\033[7;37m"
48 echo "\$ curl --version" ; curl --version
50 status_code=0
51 for tst in ./scripts/test*.sh
53 test_name="$(basename "$tst")"
54 echo -n "travis_fold:start:${test_name}\r"
55 echo -n "Running $test_name "
57 cd "$CWD"
58 # prepare a clean test environment from scratch
59 rm scripts/curl.* 1>/dev/null 2>&1
60 rm -rf WebAppRoot
61 # ...and unpack into directory 'WebAppRoot'...
62 tar -xzf source.tar.gz || { echo "ouch" && exit 1 ; }
63 mv $GITHUB_SRC_SUBDIR WebAppRoot
65 # http://robbiemackay.com/2013/05/03/automating-behat-and-mink-tests-with-travis-ci/
66 # webserver setup
67 php -S 127.0.0.1:8000 -t WebAppRoot 1> php.stdout 2> php.stderr &
68 sleep 1 # how could we get rid of this stupid sleep?
70 ls -l "WebAppRoot/index.php" >/dev/null || { echo "ouch" && exit 2 ; }
72 curl --silent --show-error \
73 --url "$BASE_URL" \
74 --data-urlencode "setlogin=$USERNAME" \
75 --data-urlencode "setpassword=$PASSWORD" \
76 --data-urlencode "continent=Europe" \
77 --data-urlencode "city=Brussels" \
78 --data-urlencode "title=Review Shaarli" \
79 --data-urlencode "Save=Save config" \
80 --output /dev/null
82 # execute each test
83 sh "$tst"
84 code=$?
86 killall php 1>/dev/null 2>&1
87 if [ $code -ne 0 ] ; then
88 for f in scripts/curl.* WebAppRoot/data/log.txt ; do
89 printf " %-60s \n" "_${f}_" | tr ' _' '# '
90 cat "$f"
91 done
92 echo ". "
94 echo -n "travis_fold:end:${test_name}\r"
96 if [ $code -eq 0 ] ; then
97 echo "${FGC_GREEN}✓${FGC_NONE} ${test_name}"
98 else
99 echo "${FGC_RED}✗${FGC_NONE} ${test_name} (code: $code)"
100 status_code=1
102 wait
103 done
105 exit $status_code