-
Notifications
You must be signed in to change notification settings - Fork 2
/
testrun
executable file
·118 lines (109 loc) · 2.32 KB
/
testrun
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
# errors on
set -e
# program name and test directory
P="$(realpath "$0")"
N="$(basename "${P}")"
D="$(dirname "${P}")"
T="${D}/tests"
# load library
LIB_SH=true
. "${D}/lib.sh"
# Override user-specified filter
export CPLR_DUMP_FILTER="cat -n -"
# runone <name>
#
# Run test NAME and check results.
#
runone() {
local name="$1"
# fail flag
local fail=""
local diff=""
# files
local fcmd="${name}.cmd"
local fout="${name}.out"
local ftmp="${name}.tmp"
local fres="${name}.res"
local fin="${name}.in"
local fdiff="${name}.diff"
# reference result
local rres=$(cat ${fres}) # evaluate
# command result
local cres=""
# check that the test exists
if ! [ -e "${fcmd}" ]; then
echo -e "\n${N}: Test '${name}' does not exist"
exit 1
fi
# run command, capture output and return value
sayn "Running test '${name}'"
set +e
. "${fcmd}" > "${ftmp}" 2>&1 < "${fin}"
cres="$?"
set -e
# compare return value
if ! [ "${cres}" = "${rres}" ]; then
fail=true
sayn ", ${red}res=${cres} expected ${rres}${normal}"
fi
# compare output
if ! cmp -s "${fout}" "${ftmp}"; then
lines="$(diff -du -I '#line [0-9]* \"internal\"$' "${fout}" "${ftmp}" | tee "${fdiff}" | wc -l)"
if [ "$lines" = "0" ]; then
if [ -z "${fail}" ]; then
fail=warn
fi
sayn ", ${yellow}line numbers changed${normal}"
else
fail=true
diff=true
sayn ", ${red}output changed${normal}"
fi
fi
# finish up
local ret="1"
local punct="."
if [ -n "${diff}" ]; then
punct=":"
fi
if [ "${fail}" = "warn" ]; then
sayn "${punct}\n"
res=0
elif [ -n "${fail}" ]; then
sayn ", ${red}fail${normal}${punct}\n"
else
sayn ", ${green}ok${normal}${punct}\n"
rm "${ftmp}"
ret=0
fi
if [ -n "${diff}" ]; then
cat "${fdiff}" | sed 's/^/ /' 1>&2
fi
return "${ret}"
}
# runsome <name>...
#
# Run given tests.
#
runsome() {
for t in "$@"; do
runone "${t}" || true
done
}
# main [<name>...]
#
# Run tests in a user-friendly way.
#
main() {
# change to test directory
cd "${T}"
# default to running all tests
if [ -z "$*" ]; then
runsome $(alltestvariants) # quoted
else
runsome "$@"
fi
}
# entry point
main "$@" || echo "FAILED"