-
Notifications
You must be signed in to change notification settings - Fork 12
/
run-tests.sh
executable file
·62 lines (52 loc) · 1.27 KB
/
run-tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# Use colors if output is terminal
if [ -t 1 ]; then
COLOR_RED="\e[0;31m"
COLOR_OFF="\e[0m"
fi
DIR=$(dirname $(readlink -f $0))
export TESTDIR="$DIR/tests"
export DATADIR="$DIR/test-data"
export BIN="$DIR/obj-magic"
export TEMPDIR=`mktemp -dt obj-magic-testing.XXXXXXXX`
LOGFILE="$TEMPDIR/test.log"
FAILS=0
echo "Starting tests @ $HOSTNAME on `date -R`"
echo "Starting tests @ $HOSTNAME on `date -R`" > "$LOGFILE"
cd "$TESTDIR"
function run_tests {
for test in `ls`; do
echo -n "Testing $test..."
echo >> "$LOGFILE"
echo "Output for test $test" >> "$LOGFILE"
bash "$test" >> "$LOGFILE" 2>&1
if [ $? -eq 0 ]; then
echo "OK"
else
echo -e "${COLOR_RED}FAIL${COLOR_OFF}"
FAILS=$(($FAILS + 1))
fi
done
# Print fail count and delete temp files on success
if [ $FAILS -gt 0 ]; then
echo -e "${COLOR_RED}${FAILS} failed tests${COLOR_OFF}"
echo "Temp files kept in $TEMPDIR"
else
echo "All tests successful"
rm -rf "$TEMPDIR"
fi
echo -n "Testing completed, elapsed time: "
return $FAILS
}
time run_tests
EXITCODE=$?
if [ $EXITCODE -gt 0 ] && [ "$CI" = "true" ]; then
echo "CI environment detected, dumping test file contents from \"$TEMPDIR\":"
cd "$TEMPDIR"
for f in `ls`; do
echo "### $f ###"
cat "$f"
echo
done
fi
exit $EXITCODE