forked from funbringer/norsu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tester.sh
executable file
·95 lines (72 loc) · 1.69 KB
/
tester.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env bash
# shellcheck disable=SC2059,SC2140
TEST_DIR="$(dirname "$0")"
export NORSU_PATH="$TEST_DIR/pg"
handler() {
rm -rf "$NORSU_PATH"
exit 1
}
trap handler SIGINT
# prepare files and dirs
mkdir -p "$TEST_DIR/results"
rm -rf "$TEST_DIR/regression.diffs"
if [ -t 1 ]; then
RED="\033[31m"
GREEN="\033[32m"
YELLOW="\033[33m"
RESET="\033[0m"
else
RED=
GREEN=
YELLOW=
RESET=
fi
TESTS_TOTAL=0
TESTS_GOOD=0
TESTS_BAD=0
echo "Norsu tester"
echo
printf "$YELLOW===== Tests: =====$RESET\\n"
echo
for t in "$TEST_DIR"/tests/*; do
NAME="$(basename "$t")"
OUT="${NAME%.*}.out"
EXPECTED="$TEST_DIR/expected/$OUT"
RESULT="$TEST_DIR/results/$OUT"
printf "Running test %s ... " "$NAME"
bash "$t" > "$RESULT" 2>&1
TESTS_TOTAL=$((TESTS_TOTAL + 1))
if [ -f "$EXPECTED" ]; then
DIFF="$(diff -u "$EXPECTED" "$RESULT")"
if [ "$DIFF" == "" ]; then
printf "$GREEN"OK"$RESET\\n"
TESTS_GOOD=$((TESTS_GOOD + 1))
else
printf "$RED"FAIL"$RESET\\n"
TESTS_BAD=$((TESTS_BAD + 1))
# append diff to regression report
echo "$DIFF" >> "$TEST_DIR/regression.diffs"
fi
else
echo
printf "\\tmissing output file %s\\n" "$EXPECTED" >&2
fi
done
# show report, if any
if [ -f regression.diffs ]; then
echo
printf "$YELLOW===== Diffs: =====$RESET\\n"
echo
cat regression.diffs
fi
echo
printf "$YELLOW===== Summary: =====$RESET\\n"
echo
echo "Total: $TESTS_TOTAL"
echo "Passed: $TESTS_GOOD"
echo "Failed: $TESTS_BAD"
echo
# report errors using non-zero exit code
if [ "$TESTS_GOOD" -lt "$TESTS_TOTAL" ]; then
exit 1
fi