blob: c5a36ad54104a32fa5c504dbc9707e3759a6af23 (
plain)
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
|
#!/usr/bin/env bash
line='........................................'
extract_section() {
local file=$1
local tag=$2
sed -ne '/^-- '"$tag"' --$/ { :n; n; /^-- End --$/b; p; b n }' "$file"
}
run_test() {
local file=$1
local name=${file##*/}
local res
printf "%s %s " "$name" "${line:${#name}}"
extract_section "$file" "Expect stdout" >"/tmp/$$.expout"
extract_section "$file" "Expect stderr" >"/tmp/$$.experr"
extract_section "$file" "Testcase" >"/tmp/$$.in"
./utpl -i "/tmp/$$.in" >"/tmp/$$.out" 2>"/tmp/$$.err"
local rc=$?
if ! cmp -s "/tmp/$$.err" "/tmp/$$.experr"; then
printf "FAILED:\n"
diff -u --color=always --label="Expected stderr" --label="Resulting stderr" "/tmp/$$.experr" "/tmp/$$.err"
printf -- "---\n"
res=1
elif ! cmp -s "/tmp/$$.out" "/tmp/$$.expout"; then
printf "FAILED:\n"
diff -u --color=always --label="Expected stdout" --label="Resulting stdout" "/tmp/$$.expout" "/tmp/$$.out"
printf -- "---\n"
res=1
#elif [ "$rc" != 0 ]; then
# local err="$(cat "/tmp/$$.err")"
# printf "FAILED:\n"
# printf "Terminated with exit code %d:\n%s\n---\n" $rc "${err:-(no error output)}"
# res=1
else
printf "OK\n"
res=0
fi
rm -f "/tmp/$$.in" "/tmp/$$.out" "/tmp/$$.err" "/tmp/$$.expout" "/tmp/$$.experr"
return $res
}
n_tests=0
n_fails=0
for catdir in tests/[0-9][0-9]_*; do
[ -d "$catdir" ] || continue
printf "\n##\n## Running %s tests\n##\n\n" "${catdir##*/[0-9][0-9]_}"
for testfile in "$catdir/"[0-9][0-9]_*; do
[ -f "$testfile" ] || continue
n_tests=$((n_tests + 1))
run_test "$testfile" || n_fails=$((n_fails + 1))
done
done
printf "\nRan %d tests, %d okay, %d failures\n" $n_tests $((n_tests - n_fails)) $n_fails
|