run_test.sh revision 1.1.1.8.16.1 1 1.1 christos #!/bin/sh
2 1.1.1.8.16.1 martin # Id: run_test.sh,v 1.29 2019/06/17 08:12:47 tom Exp
3 1.1.1.2 christos # vi:ts=4 sw=4:
4 1.1.1.2 christos
5 1.1.1.6 christos errors=0
6 1.1.1.6 christos
7 1.1.1.6 christos # NEW is the file created by the testcase
8 1.1.1.6 christos # REF is the reference file against which to compare
9 1.1.1.6 christos test_diffs() {
10 1.1.1.6 christos # echo "...test_diffs $NEW vs $REF"
11 1.1.1.6 christos mv -f $NEW ${REF_DIR}/
12 1.1.1.6 christos CMP=${REF_DIR}/${NEW}
13 1.1.1.6 christos if test ! -f $CMP
14 1.1.1.6 christos then
15 1.1.1.6 christos echo "...not found $CMP"
16 1.1.1.6 christos errors=1
17 1.1.1.6 christos else
18 1.1.1.6 christos sed -e s,$NEW,$REF, \
19 1.1.1.6 christos -e "s%$YACC_escaped%YACC%" \
20 1.1.1.6 christos -e '/YYPATCH/s/[0-9][0-9]*/"yyyymmdd"/' \
21 1.1.1.6 christos -e '/#define YYPATCH/s/PATCH/CHECK/' \
22 1.1.1.6 christos -e 's,#line \([1-9][0-9]*\) "'$REF_DIR'/,#line \1 ",' \
23 1.1.1.6 christos -e 's,#line \([1-9][0-9]*\) "'$TEST_DIR'/,#line \1 ",' \
24 1.1.1.6 christos -e 's,\(YACC:.* line [0-9][0-9]* of "\)'$TEST_DIR/',\1./,' \
25 1.1.1.6 christos < $CMP >$tmpfile \
26 1.1.1.6 christos && mv $tmpfile $CMP
27 1.1.1.6 christos if test ! -f $REF
28 1.1.1.6 christos then
29 1.1.1.6 christos mv $CMP $REF
30 1.1.1.6 christos echo "...saved $REF"
31 1.1.1.6 christos elif ( cmp -s $REF $CMP )
32 1.1.1.6 christos then
33 1.1.1.6 christos echo "...ok $REF"
34 1.1.1.6 christos rm -f $CMP
35 1.1.1.6 christos else
36 1.1.1.6 christos echo "...diff $REF"
37 1.1.1.6 christos diff -u $REF $CMP
38 1.1.1.6 christos errors=1
39 1.1.1.6 christos fi
40 1.1.1.6 christos fi
41 1.1.1.6 christos }
42 1.1.1.6 christos
43 1.1.1.6 christos test_flags() {
44 1.1.1.6 christos echo "** testing flags $*"
45 1.1.1.6 christos root=$1
46 1.1.1.6 christos ROOT=test-$root
47 1.1.1.6 christos shift 1
48 1.1.1.8.16.1 martin $YACC "$@" >$ROOT.output 2>$ROOT.error
49 1.1.1.6 christos for type in .output .error
50 1.1.1.6 christos do
51 1.1.1.6 christos NEW=$ROOT$type
52 1.1.1.6 christos REF=$REF_DIR/$root$type
53 1.1.1.6 christos test_diffs
54 1.1.1.6 christos done
55 1.1.1.6 christos }
56 1.1.1.6 christos
57 1.1.1.8.16.1 martin test_stdin() {
58 1.1.1.8.16.1 martin echo "** testing stdin $*"
59 1.1.1.8.16.1 martin root=$1
60 1.1.1.8.16.1 martin ROOT=test-$root
61 1.1.1.8.16.1 martin shift 1
62 1.1.1.8.16.1 martin opts="$1"
63 1.1.1.8.16.1 martin shift 1
64 1.1.1.8.16.1 martin code=`echo "$1"|sed -e 's/y$/c/' -e "s,${TEST_DIR}/,,"`
65 1.1.1.8.16.1 martin if test "x$opts" = "x-"
66 1.1.1.8.16.1 martin then
67 1.1.1.8.16.1 martin $YACC -o $ROOT.$code $opts <$1 >$ROOT.output 2>$ROOT.error
68 1.1.1.8.16.1 martin else
69 1.1.1.8.16.1 martin $YACC -o $ROOT.$code $opts $1 >$ROOT.output 2>$ROOT.error
70 1.1.1.8.16.1 martin fi
71 1.1.1.8.16.1 martin for type in .output .error .$code
72 1.1.1.8.16.1 martin do
73 1.1.1.8.16.1 martin NEW=$ROOT$type
74 1.1.1.8.16.1 martin REF=$REF_DIR/$root$type
75 1.1.1.8.16.1 martin test_diffs
76 1.1.1.8.16.1 martin done
77 1.1.1.8.16.1 martin }
78 1.1.1.8.16.1 martin
79 1.1.1.8.16.1 martin test_defines() {
80 1.1.1.8.16.1 martin echo "** testing defines $*"
81 1.1.1.8.16.1 martin root=$1
82 1.1.1.8.16.1 martin ROOT=test-$root
83 1.1.1.8.16.1 martin shift 1
84 1.1.1.8.16.1 martin opts=
85 1.1.1.8.16.1 martin while test $# != 1
86 1.1.1.8.16.1 martin do
87 1.1.1.8.16.1 martin opts="$opts $1"
88 1.1.1.8.16.1 martin shift 1
89 1.1.1.8.16.1 martin done
90 1.1.1.8.16.1 martin head=`echo "$1"|sed -e 's/y$/h/' -e "s,${TEST_DIR}/,,"`
91 1.1.1.8.16.1 martin code=`echo "$1"|sed -e 's/y$/c/' -e "s,${TEST_DIR}/,,"`
92 1.1.1.8.16.1 martin $YACC $opts -H $ROOT.$head $1 >$ROOT.output 2>$ROOT.error
93 1.1.1.8.16.1 martin for name in prefix.tab.c y.tab.c
94 1.1.1.8.16.1 martin do
95 1.1.1.8.16.1 martin if test -f $name
96 1.1.1.8.16.1 martin then
97 1.1.1.8.16.1 martin mv $name $ROOT.$code
98 1.1.1.8.16.1 martin break
99 1.1.1.8.16.1 martin fi
100 1.1.1.8.16.1 martin done
101 1.1.1.8.16.1 martin for name in .output .error .$head .$code
102 1.1.1.8.16.1 martin do
103 1.1.1.8.16.1 martin NEW=$ROOT$name
104 1.1.1.8.16.1 martin REF=$REF_DIR/$root$name
105 1.1.1.8.16.1 martin test_diffs
106 1.1.1.8.16.1 martin done
107 1.1.1.8.16.1 martin }
108 1.1.1.8.16.1 martin
109 1.1.1.2 christos if test $# = 1
110 1.1.1.2 christos then
111 1.1.1.2 christos PROG_DIR=`pwd`
112 1.1.1.2 christos TEST_DIR=$1
113 1.1.1.6 christos PROG_DIR=`echo "$PROG_DIR" | sed -e 's/ /\\\\ /g'`
114 1.1.1.6 christos TEST_DIR=`echo "$TEST_DIR" | sed -e 's/ /\\\\ /g'`
115 1.1.1.2 christos else
116 1.1.1.2 christos PROG_DIR=..
117 1.1.1.2 christos TEST_DIR=.
118 1.1.1.2 christos fi
119 1.1.1.2 christos
120 1.1.1.2 christos YACC=$PROG_DIR/yacc
121 1.1.1.6 christos YACC_escaped=`echo "$PROG_DIR/yacc" | sed -e 's/\./\\\./g'`
122 1.1.1.2 christos
123 1.1.1.2 christos tmpfile=temp$$
124 1.1.1.6 christos
125 1.1.1.6 christos ifBTYACC=`fgrep -l 'define YYBTYACC' $PROG_DIR/config.h > /dev/null; test $? != 0; echo $?`
126 1.1.1.6 christos
127 1.1.1.6 christos if test $ifBTYACC = 0; then
128 1.1.1.6 christos REF_DIR=${TEST_DIR}/yacc
129 1.1.1.6 christos else
130 1.1.1.6 christos REF_DIR=${TEST_DIR}/btyacc
131 1.1.1.6 christos fi
132 1.1.1.6 christos
133 1.1.1.6 christos rm -f ${REF_DIR}/test-*
134 1.1.1.2 christos
135 1.1 christos echo '** '`date`
136 1.1.1.6 christos
137 1.1.1.6 christos # Tests which do not need files
138 1.1.1.6 christos MYFILE=nosuchfile
139 1.1.1.6 christos test_flags help -z
140 1.1.1.6 christos test_flags big_b -B
141 1.1.1.6 christos test_flags big_l -L
142 1.1.1.6 christos
143 1.1.1.6 christos # Test attempts to read non-existent file
144 1.1.1.6 christos rm -f $MYFILE.*
145 1.1.1.6 christos test_flags nostdin - $MYFILE.y
146 1.1.1.6 christos test_flags no_opts -- $MYFILE.y
147 1.1.1.6 christos
148 1.1.1.6 christos # Test attempts to write to readonly file
149 1.1.1.6 christos touch $MYFILE.y
150 1.1.1.6 christos
151 1.1.1.6 christos touch $MYFILE.c
152 1.1.1.6 christos chmod 444 $MYFILE.*
153 1.1.1.6 christos test_flags no_b_opt -b
154 1.1.1.6 christos test_flags no_b_opt1 -bBASE -o $MYFILE.c $MYFILE.y
155 1.1.1.6 christos
156 1.1.1.6 christos touch $MYFILE.c
157 1.1.1.6 christos chmod 444 $MYFILE.*
158 1.1.1.6 christos test_flags no_p_opt -p
159 1.1.1.6 christos test_flags no_p_opt1 -pBASE -o $MYFILE.c $MYFILE.y
160 1.1.1.6 christos rm -f BASE$MYFILE.c
161 1.1.1.6 christos
162 1.1.1.6 christos touch $MYFILE.dot
163 1.1.1.6 christos chmod 444 $MYFILE.*
164 1.1.1.6 christos test_flags no_graph -g -o $MYFILE.c $MYFILE.y
165 1.1.1.6 christos rm -f $MYFILE.dot
166 1.1.1.6 christos
167 1.1.1.6 christos touch $MYFILE.output
168 1.1.1.6 christos chmod 444 $MYFILE.*
169 1.1.1.6 christos test_flags no_verbose -v -o $MYFILE.c $MYFILE.y
170 1.1.1.6 christos test_flags no_output -o $MYFILE.output $MYFILE.y
171 1.1.1.6 christos test_flags no_output1 -o$MYFILE.output $MYFILE.y
172 1.1.1.6 christos test_flags no_output2 -o
173 1.1.1.6 christos rm -f $MYFILE.output
174 1.1.1.6 christos
175 1.1.1.6 christos touch $MYFILE.h
176 1.1.1.6 christos chmod 444 $MYFILE.*
177 1.1.1.6 christos test_flags no_defines -d -o $MYFILE.c $MYFILE.y
178 1.1.1.6 christos rm -f $MYFILE.h
179 1.1.1.6 christos
180 1.1.1.6 christos touch $MYFILE.i
181 1.1.1.6 christos chmod 444 $MYFILE.*
182 1.1.1.6 christos test_flags no_include -i -o $MYFILE.c $MYFILE.y
183 1.1.1.6 christos rm -f $MYFILE.i
184 1.1.1.6 christos
185 1.1.1.6 christos touch $MYFILE.code.c
186 1.1.1.6 christos chmod 444 $MYFILE.*
187 1.1.1.6 christos test_flags no_code_c -r -o $MYFILE.c $MYFILE.y
188 1.1.1.6 christos rm -f $MYFILE.code.c
189 1.1.1.6 christos
190 1.1.1.6 christos rm -f $MYFILE.*
191 1.1.1.6 christos
192 1.1.1.8.16.1 martin # Test special cases
193 1.1.1.8.16.1 martin test_stdin stdin1 - ${TEST_DIR}/calc.y
194 1.1.1.8.16.1 martin test_stdin stdin2 -- ${TEST_DIR}/calc.y
195 1.1.1.8.16.1 martin
196 1.1.1.8.16.1 martin test_defines defines1 ${TEST_DIR}/calc.y
197 1.1.1.8.16.1 martin test_defines defines2 -d ${TEST_DIR}/calc.y
198 1.1.1.8.16.1 martin test_defines defines3 -b prefix ${TEST_DIR}/calc.y
199 1.1.1.8.16.1 martin
200 1.1.1.5 christos for input in ${TEST_DIR}/*.y
201 1.1 christos do
202 1.1.1.5 christos case $input in
203 1.1.1.6 christos test-*)
204 1.1.1.5 christos echo "?? ignored $input"
205 1.1 christos ;;
206 1.1 christos *)
207 1.1.1.5 christos root=`basename $input .y`
208 1.1 christos ROOT="test-$root"
209 1.1.1.2 christos prefix=${root}_
210 1.1.1.2 christos
211 1.1.1.2 christos OPTS=
212 1.1.1.5 christos OPT2=
213 1.1.1.6 christos OOPT=
214 1.1.1.6 christos TYPE=".error .output .tab.c .tab.h"
215 1.1.1.5 christos case $input in
216 1.1.1.6 christos ${TEST_DIR}/btyacc_*)
217 1.1.1.6 christos if test $ifBTYACC = 0; then continue; fi
218 1.1.1.6 christos OPTS="$OPTS -B"
219 1.1.1.6 christos prefix=`echo "$prefix" | sed -e 's/^btyacc_//'`
220 1.1.1.6 christos ;;
221 1.1.1.6 christos ${TEST_DIR}/grammar*)
222 1.1.1.6 christos OPTS="$OPTS -g"
223 1.1.1.6 christos TYPE="$TYPE .dot"
224 1.1.1.6 christos ;;
225 1.1.1.6 christos ${TEST_DIR}/code_debug*)
226 1.1.1.6 christos OPTS="$OPTS -t -i"
227 1.1.1.6 christos OOPT=rename_debug.c
228 1.1.1.6 christos TYPE="$TYPE .i"
229 1.1.1.6 christos prefix=
230 1.1.1.6 christos ;;
231 1.1.1.2 christos ${TEST_DIR}/code_*)
232 1.1.1.2 christos OPTS="$OPTS -r"
233 1.1.1.2 christos TYPE="$TYPE .code.c"
234 1.1.1.2 christos prefix=`echo "$prefix" | sed -e 's/^code_//'`
235 1.1.1.2 christos ;;
236 1.1.1.2 christos ${TEST_DIR}/pure_*)
237 1.1.1.2 christos OPTS="$OPTS -P"
238 1.1.1.2 christos prefix=`echo "$prefix" | sed -e 's/^pure_//'`
239 1.1.1.2 christos ;;
240 1.1.1.5 christos ${TEST_DIR}/quote_*)
241 1.1.1.5 christos OPT2="-s"
242 1.1.1.5 christos ;;
243 1.1.1.6 christos ${TEST_DIR}/inherit*|\
244 1.1.1.6 christos ${TEST_DIR}/err_inherit*)
245 1.1.1.6 christos if test $ifBTYACC = 0; then continue; fi
246 1.1.1.6 christos ;;
247 1.1.1.2 christos esac
248 1.1.1.2 christos
249 1.1.1.6 christos echo "** testing $input"
250 1.1.1.6 christos
251 1.1.1.6 christos test -n "$prefix" && prefix="-p $prefix"
252 1.1.1.6 christos
253 1.1.1.5 christos for opt2 in "" $OPT2
254 1.1 christos do
255 1.1.1.6 christos output=$OOPT
256 1.1.1.6 christos if test -n "$output"
257 1.1.1.6 christos then
258 1.1.1.6 christos output="-o $output"
259 1.1.1.6 christos error=`basename $OOPT .c`.error
260 1.1.1.6 christos else
261 1.1.1.6 christos error=${ROOT}${opt2}.error
262 1.1.1.6 christos fi
263 1.1.1.6 christos
264 1.1.1.6 christos $YACC $OPTS $opt2 -v -d $output $prefix -b $ROOT${opt2} $input 2>$error
265 1.1.1.5 christos for type in $TYPE
266 1.1.1.5 christos do
267 1.1.1.6 christos REF=${REF_DIR}/${root}${opt2}${type}
268 1.1.1.6 christos
269 1.1.1.6 christos # handle renaming due to "-o" option
270 1.1.1.6 christos if test -n "$OOPT"
271 1.1.1.5 christos then
272 1.1.1.6 christos case $type in
273 1.1.1.6 christos *.tab.c)
274 1.1.1.6 christos type=.c
275 1.1.1.6 christos ;;
276 1.1.1.6 christos *.tab.h)
277 1.1.1.6 christos type=.h
278 1.1.1.6 christos ;;
279 1.1.1.6 christos *)
280 1.1.1.6 christos ;;
281 1.1.1.6 christos esac
282 1.1.1.6 christos NEW=`basename $OOPT .c`${type}
283 1.1.1.6 christos case $NEW in
284 1.1.1.6 christos test-*)
285 1.1.1.6 christos ;;
286 1.1.1.6 christos *)
287 1.1.1.6 christos if test -f "$NEW"
288 1.1.1.6 christos then
289 1.1.1.6 christos REF=${REF_DIR}/$NEW
290 1.1.1.6 christos mv $NEW test-$NEW
291 1.1.1.6 christos NEW=test-$NEW
292 1.1.1.6 christos fi
293 1.1.1.6 christos ;;
294 1.1.1.6 christos esac
295 1.1.1.5 christos else
296 1.1.1.6 christos NEW=${ROOT}${opt2}${type}
297 1.1.1.5 christos fi
298 1.1.1.6 christos test_diffs
299 1.1.1.5 christos done
300 1.1 christos done
301 1.1 christos ;;
302 1.1 christos esac
303 1.1 christos done
304 1.1.1.6 christos
305 1.1.1.6 christos exit $errors
306