-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtestman
executable file
·206 lines (190 loc) · 5.91 KB
/
testman
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/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 -"
# genvariant <name> <options> <command>...
#
# Generate or regenerate a test variant.
#
genvariant() {
local vname="$1"
local vopts="$2" # always 'ignore' when command given
shift 2
# command result
local cres=""
# run test and create reference
if [ -n "$*" ]; then
# generation - use new data
echo "Generating test variant '${vname}'"
# save the command
( nquote "$@"; echo ) > "${vname}.cmd"
# run the test
tee "${vname}.in" | (
set +e
eval "$@" 2>&1
echo "$?" > "${vname}.res"
set -e
) | tee "${vname}.out"
else
# regeneration - use existing data
echo "Regenerating test variant '${vname}'"
# run the test
(
set +e
. "${vname}.cmd" 2>&1
echo "$?" > "${vname}.res"
set -e
) < "${vname}.in" | tee "${vname}.out"
fi
# report and store result code
cres="$(cat "${vname}.res")"
echo "Result: ${cres}"
echo "${cres}" > "${vname}.res"
}
gentest() {
local name="$1"
shift 1
# name of base test
local base="${name}.base"
if [ -n "$*" ]; then
# generating new test
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! GENERATING ${name}"
# capture input
tee "${base}.in"
else
# regenerating existing test
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! REGENERATING ${name}"
fi
echo ""
# generate variants
local opts=""
local vname=""
local vopts=""
for d in "" d; do
for n in "" n; do
for p in "" p; do
for v in "" v vv; do
# determine name and options
opts="$d$n$p$v"
vopts=""
if [ -z "${opts}" ]; then
vname="${base}"
else
vname="${name}.variant.$d$n$p$v"
vopts="-$d$n$p$v"
fi
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! VARIANT ${vname}"
# take care of automatic variants
if [ -n "${opts}" ]; then
# link the input
ln -f -s "${base}.in" "${vname}.in"
sed 's/\w+#.*$//' "${base}.cmd" | (
local done=""
while read -r line; do
if (echo "${line}" | grep -q " \-\-"); then
#say "case a: ${line}"
echo "${line}" | sed "s/ --/ ${vopts} --/"
done=true
elif [ -n "${done}" ] || (echo "${line}" | grep -q -e '[\\]$' -e '^[[:space:]]*$'); then
#say "case b: ${line}"
# empty lines and continued lines copied verbatim
echo "${line}"
else
#say "case c: ${line}"
printf '%s %q\n' "${line}" "${vopts}"
done=true
fi
done
) | tee "${vname}.cmd"
fi
echo ""
if [ -z "${vopts}" ]; then
genvariant "${vname}" "ignore" "$@" < "${vname}.in"
else
genvariant "${vname}" "${vopts}" < "${vname}.in"
fi
echo ""
done
done
done
done
}
main() {
local command="$1"
if [ -n "${command}" ]; then
shift 1
fi
# change to test directory
cd "${T}"
# check arguments
if [ "${command}" = "ls" ]; then
for test in $(alltests); do
echo "${test}"
done
elif [ "${command}" = "gen" ]; then
local name="$1"
if [ -n "${name}" ]; then
shift 1
fi
local tests="$@"
if [ -z "${name}" ] || [ "${name}" = "all" ]; then
tests="$(alltests)"
fi
for test in ${tests}; do
gentest "${test}"
done
elif [ "${command}" = "new" ]; then
local name="$1"
shift 1
gentest ${name} "$@"
elif [ "${command}" = "edit" ]; then
local test="$1"
if [ -z "${test}" ]; then
command="help"
else
local file="$2"
if [ -z "${file}" ]; then
file="cmd"
fi
local path="${test}.base.${file}"
local stamp=".edit.stamp"
touch "${stamp}"
run_editor "${path}" && if [ "${path}" -nt "${stamp}" ]; then
gentest "${test}"
fi && rm -f "${stamp}" *~
fi
else
command="help"
fi
if [ "${command}" = "help" ] || [ "${command}" = "-h" ] || [ -z "${command}" ]; then
echo "Usage:"
echo " ${N} ls "
echo " List all base tests."
echo ""
echo " ${N} new <name> <command>..."
echo " Execute COMMAND and generate test reference."
echo " User must provide INPUT. Use 'echo' as dummy."
echo ""
echo " ${N} edit <name> [<file>]"
echo " Edit file associated with test NAME."
echo " Allowed files: cmd, in"
echo " Test will be regenerated automatically if changed."
echo ""
echo " ${N} gen [all | <name>...]"
echo " Regenerate test reference from stored commands."
echo " If no names are provided then all tests will regen."
echo ""
return 1
fi
}
# entry point
main "$@"