-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregress.sh
270 lines (216 loc) · 5.39 KB
/
regress.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
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/bin/sh
#-
# Copyright (c) 2018, 2021 Antti Kantee <[email protected]>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# assume this is run in the top level test directory
export PYTHONPATH=..
export PATH="../bin:${PATH}"
die ()
{
echo '>>' $* 1>&2
exit 1
}
msg ()
{
echo '>>' $* 1>&2
}
usage ()
{
die usage: $0 prep\|test\|reset
}
_prep ()
{
isrecipe=$1
shift
descr=$1
shift
tn="${descr}-${num}"
echo "=== ${tn} ==="
echo "${@}" > testdata/${tn}.cmd
if ${PREP}; then
echo "==> ${*}"
${@} > testdata/${tn}.out
[ $? -eq 0 ] || die Failed: $(cat testdata/${tn}).out
! ${isrecipe}|| echo $(eval echo \${$#}) >testdata/${tn}.recipe
fi
num=$((${num} + 1))
}
prepcmd ()
{
_prep false "$@"
}
preprecipe ()
{
_prep true "$@"
}
resetcount ()
{
num=1
}
doprep ()
{
! ${PREP} || [ ! -d testdata ] \
|| die testdata already exists. \"reset\" first
mkdir -p testdata || die cannot create testdata
resetcount
# hack: make sure at least one recipe is tested first
preprecipe 0basicrecipe wbcrecipe -p params-std \
test-recipes/proto-bymass.yaml
resetcount
for x in compiled-recipes/*.yaml; do
[ -f ${x} ] || die internal error: ${x}
preprecipe recipe-std wbcrecipe -p params-std ${x}
done
resetcount
for x in compiled-recipes/*mish,step*.yaml; do
[ -f ${x} ] || die internal error: ${x}
preprecipe recipe-alt wbcrecipe -p params-mltdirect+sg+us \
-i mashheat.yaml ${x}
done
resetcount
preprecipe vol wbcrecipe -v 30l -p params-std \
test-recipes/proto-bymass.yaml
preprecipe vol wbcrecipe -V 30l -p params-std \
test-recipes/proto-bymass.yaml
preprecipe vol wbcrecipe -v 40l -P bM=35L -p params-std \
test-recipes/proto-bymass.yaml
resetcount
preprecipe noboil wbcrecipe -p params-std \
test-recipes/proto-bymass-noboil.yaml
preprecipe noboil wbcrecipe -p params-std \
test-recipes/proto-bymass-0boil.yaml
resetcount
preprecipe nomash-mass wbcrecipe -p params-std \
test-recipes/proto-bymass-nomash.yaml
preprecipe nomash-mass wbcrecipe -p params-std \
test-recipes/proto-bymass-extract.yaml
preprecipe nomash-mass wbcrecipe -p params-std \
test-recipes/proto-bymass-steepextract.yaml
resetcount
preprecipe nomash-percent wbcrecipe -p params-std \
test-recipes/proto-bypercent-extract.yaml
preprecipe nomash-percent wbcrecipe -p params-std \
test-recipes/proto-bypercent-steepextract.yaml
resetcount
preprecipe pagelen wbcrecipe -p params-std -P oP=10 \
test-recipes/proto-bymass.yaml
preprecipe pagelen wbcrecipe -p params-std -P oP=40 \
test-recipes/proto-bymass.yaml
preprecipe pagelen wbcrecipe -p params-std -P oP=400 \
test-recipes/proto-bymass.yaml
resetcount
preprecipe liquid-maximum wbcrecipe -p params-std \
test-recipes/applewine.yaml
preprecipe liquid-maximum wbcrecipe -p params-std \
test-recipes/cidre-fermenter.yaml
resetcount
while read line; do
set -- ${line}
[ $# -ne 0 ] || continue
prepcmd cmdregress ${line}
done < cmds-regress.txt
}
checkfails ()
{
what=$1
file=$2
[ ! -f ${file} ] || { \
msg ; msg ${what} failed \(n = $(wc -l ${file})\):;
cat ${file} | while read x ; do
echo -n "${x}: "
cat testdata/${x}.cmd
done }
}
_onetest ()
{
tname=$1
storeres=$2
read cmd < testdata/${tname}.cmd
echo "==== ${cmd}"
set -- ${cmd}
rv=1
${@} > testdata/${tname}.cmp
if [ $? -ne 0 ]; then
! ${storeres} || echo ${tname} >> ${ft}
elif ! diff -u testdata/${tname}.out testdata/${tname}.cmp; then
! ${storeres} || echo ${tname} >> ${fc}
else
rv=0
fi
return ${rv}
}
dotest ()
{
[ -n "$(ls testdata 2>/dev/null)" ] \
|| die no testdata, did not run prep\?
ft=testdata/failed-tests
fc=testdata/failed-comps
rm -f ${ft} ${fc}
for x in testdata/*.cmd; do
bn=$(basename ${x%.cmd})
_onetest ${bn} true
if [ $? -ne 0 ]; then
if ${VERBOSE} && [ -f testdata/${bn}.recipe ]; then
echo '------ BEGIN RECIPE ------'
cat $(cat testdata/${bn}.recipe)
echo '------ END RECIPE ------'
fi
${FATAL}
fi
done
checkfails Comparisons ${fc}
checkfails Tests ${ft}
[ ! -f ${ft} -a ! -f ${fc} ] || die 'failed'
echo '>> no regressions. run "reset" if you no longer need testdata'
}
doreset ()
{
rm -rf testdata
}
#
# BEGIN script
#
FATAL=:
VERBOSE=false
while getopts 'fv' opt; do
case "$opt" in
f) FATAL='exit 1';;
v) VERBOSE=true;;
esac
done
shift $((${OPTIND} - 1))
# onetest takes two arguments
if [ "$1" = 'onetest' ]; then
[ $# -eq 2 ] || usage
_onetest $2 false
[ $? -eq 0 ] || { echo 'FAILED' ; exit 1 ; }
exit 0
fi
[ $# -eq 1 ] || usage
if [ "$1" = 'prep' ]; then
PREP=true
doprep
elif [ $1 = '_recmd' ]; then
PREP=false
doprep
elif [ $1 = 'test' ]; then
dotest
elif [ $1 = 'reset' ]; then
doreset
else
msg invalid command $1
usage
fi
exit 0