run_test.sh revision 1.1.1.7 1 1.1 christos #!/bin/sh
2 1.1.1.7 christos # $Id: run_test.sh,v 1.1.1.7 2016/01/09 21:55:11 christos 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.6 christos $YACC $* >$ROOT.output \
49 1.1.1.6 christos 2>&1 >$ROOT.error
50 1.1.1.6 christos for type in .output .error
51 1.1.1.6 christos do
52 1.1.1.6 christos NEW=$ROOT$type
53 1.1.1.6 christos REF=$REF_DIR/$root$type
54 1.1.1.6 christos test_diffs
55 1.1.1.6 christos done
56 1.1.1.6 christos }
57 1.1.1.6 christos
58 1.1.1.2 christos if test $# = 1
59 1.1.1.2 christos then
60 1.1.1.2 christos PROG_DIR=`pwd`
61 1.1.1.2 christos TEST_DIR=$1
62 1.1.1.6 christos PROG_DIR=`echo "$PROG_DIR" | sed -e 's/ /\\\\ /g'`
63 1.1.1.6 christos TEST_DIR=`echo "$TEST_DIR" | sed -e 's/ /\\\\ /g'`
64 1.1.1.2 christos else
65 1.1.1.2 christos PROG_DIR=..
66 1.1.1.2 christos TEST_DIR=.
67 1.1.1.2 christos fi
68 1.1.1.2 christos
69 1.1.1.2 christos YACC=$PROG_DIR/yacc
70 1.1.1.6 christos YACC_escaped=`echo "$PROG_DIR/yacc" | sed -e 's/\./\\\./g'`
71 1.1.1.2 christos
72 1.1.1.2 christos tmpfile=temp$$
73 1.1.1.6 christos
74 1.1.1.6 christos ifBTYACC=`fgrep -l 'define YYBTYACC' $PROG_DIR/config.h > /dev/null; test $? != 0; echo $?`
75 1.1.1.6 christos
76 1.1.1.6 christos if test $ifBTYACC = 0; then
77 1.1.1.6 christos REF_DIR=${TEST_DIR}/yacc
78 1.1.1.6 christos else
79 1.1.1.6 christos REF_DIR=${TEST_DIR}/btyacc
80 1.1.1.6 christos fi
81 1.1.1.6 christos
82 1.1.1.6 christos rm -f ${REF_DIR}/test-*
83 1.1.1.2 christos
84 1.1 christos echo '** '`date`
85 1.1.1.6 christos
86 1.1.1.6 christos # Tests which do not need files
87 1.1.1.6 christos MYFILE=nosuchfile
88 1.1.1.6 christos test_flags help -z
89 1.1.1.6 christos test_flags big_b -B
90 1.1.1.6 christos test_flags big_l -L
91 1.1.1.6 christos
92 1.1.1.6 christos # Test attempts to read non-existent file
93 1.1.1.6 christos rm -f $MYFILE.*
94 1.1.1.6 christos test_flags nostdin - $MYFILE.y
95 1.1.1.6 christos test_flags no_opts -- $MYFILE.y
96 1.1.1.6 christos
97 1.1.1.6 christos # Test attempts to write to readonly file
98 1.1.1.6 christos touch $MYFILE.y
99 1.1.1.6 christos
100 1.1.1.6 christos touch $MYFILE.c
101 1.1.1.6 christos chmod 444 $MYFILE.*
102 1.1.1.6 christos test_flags no_b_opt -b
103 1.1.1.6 christos test_flags no_b_opt1 -bBASE -o $MYFILE.c $MYFILE.y
104 1.1.1.6 christos
105 1.1.1.6 christos touch $MYFILE.c
106 1.1.1.6 christos chmod 444 $MYFILE.*
107 1.1.1.6 christos test_flags no_p_opt -p
108 1.1.1.6 christos test_flags no_p_opt1 -pBASE -o $MYFILE.c $MYFILE.y
109 1.1.1.6 christos rm -f BASE$MYFILE.c
110 1.1.1.6 christos
111 1.1.1.6 christos touch $MYFILE.dot
112 1.1.1.6 christos chmod 444 $MYFILE.*
113 1.1.1.6 christos test_flags no_graph -g -o $MYFILE.c $MYFILE.y
114 1.1.1.6 christos rm -f $MYFILE.dot
115 1.1.1.6 christos
116 1.1.1.6 christos touch $MYFILE.output
117 1.1.1.6 christos chmod 444 $MYFILE.*
118 1.1.1.6 christos test_flags no_verbose -v -o $MYFILE.c $MYFILE.y
119 1.1.1.6 christos test_flags no_output -o $MYFILE.output $MYFILE.y
120 1.1.1.6 christos test_flags no_output1 -o$MYFILE.output $MYFILE.y
121 1.1.1.6 christos test_flags no_output2 -o
122 1.1.1.6 christos rm -f $MYFILE.output
123 1.1.1.6 christos
124 1.1.1.6 christos touch $MYFILE.h
125 1.1.1.6 christos chmod 444 $MYFILE.*
126 1.1.1.6 christos test_flags no_defines -d -o $MYFILE.c $MYFILE.y
127 1.1.1.6 christos rm -f $MYFILE.h
128 1.1.1.6 christos
129 1.1.1.6 christos touch $MYFILE.i
130 1.1.1.6 christos chmod 444 $MYFILE.*
131 1.1.1.6 christos test_flags no_include -i -o $MYFILE.c $MYFILE.y
132 1.1.1.6 christos rm -f $MYFILE.i
133 1.1.1.6 christos
134 1.1.1.6 christos touch $MYFILE.code.c
135 1.1.1.6 christos chmod 444 $MYFILE.*
136 1.1.1.6 christos test_flags no_code_c -r -o $MYFILE.c $MYFILE.y
137 1.1.1.6 christos rm -f $MYFILE.code.c
138 1.1.1.6 christos
139 1.1.1.6 christos rm -f $MYFILE.*
140 1.1.1.6 christos
141 1.1.1.5 christos for input in ${TEST_DIR}/*.y
142 1.1 christos do
143 1.1.1.5 christos case $input in
144 1.1.1.6 christos test-*)
145 1.1.1.5 christos echo "?? ignored $input"
146 1.1 christos ;;
147 1.1 christos *)
148 1.1.1.5 christos root=`basename $input .y`
149 1.1 christos ROOT="test-$root"
150 1.1.1.2 christos prefix=${root}_
151 1.1.1.2 christos
152 1.1.1.2 christos OPTS=
153 1.1.1.5 christos OPT2=
154 1.1.1.6 christos OOPT=
155 1.1.1.6 christos TYPE=".error .output .tab.c .tab.h"
156 1.1.1.5 christos case $input in
157 1.1.1.6 christos ${TEST_DIR}/btyacc_*)
158 1.1.1.6 christos if test $ifBTYACC = 0; then continue; fi
159 1.1.1.6 christos OPTS="$OPTS -B"
160 1.1.1.6 christos prefix=`echo "$prefix" | sed -e 's/^btyacc_//'`
161 1.1.1.6 christos ;;
162 1.1.1.6 christos ${TEST_DIR}/grammar*)
163 1.1.1.6 christos OPTS="$OPTS -g"
164 1.1.1.6 christos TYPE="$TYPE .dot"
165 1.1.1.6 christos ;;
166 1.1.1.6 christos ${TEST_DIR}/code_debug*)
167 1.1.1.6 christos OPTS="$OPTS -t -i"
168 1.1.1.6 christos OOPT=rename_debug.c
169 1.1.1.6 christos TYPE="$TYPE .i"
170 1.1.1.6 christos prefix=
171 1.1.1.6 christos ;;
172 1.1.1.2 christos ${TEST_DIR}/code_*)
173 1.1.1.2 christos OPTS="$OPTS -r"
174 1.1.1.2 christos TYPE="$TYPE .code.c"
175 1.1.1.2 christos prefix=`echo "$prefix" | sed -e 's/^code_//'`
176 1.1.1.2 christos ;;
177 1.1.1.2 christos ${TEST_DIR}/pure_*)
178 1.1.1.2 christos OPTS="$OPTS -P"
179 1.1.1.2 christos prefix=`echo "$prefix" | sed -e 's/^pure_//'`
180 1.1.1.2 christos ;;
181 1.1.1.5 christos ${TEST_DIR}/quote_*)
182 1.1.1.5 christos OPT2="-s"
183 1.1.1.5 christos ;;
184 1.1.1.6 christos ${TEST_DIR}/inherit*|\
185 1.1.1.6 christos ${TEST_DIR}/err_inherit*)
186 1.1.1.6 christos if test $ifBTYACC = 0; then continue; fi
187 1.1.1.6 christos ;;
188 1.1.1.2 christos esac
189 1.1.1.2 christos
190 1.1.1.6 christos echo "** testing $input"
191 1.1.1.6 christos
192 1.1.1.6 christos test -n "$prefix" && prefix="-p $prefix"
193 1.1.1.6 christos
194 1.1.1.5 christos for opt2 in "" $OPT2
195 1.1 christos do
196 1.1.1.6 christos output=$OOPT
197 1.1.1.6 christos if test -n "$output"
198 1.1.1.6 christos then
199 1.1.1.6 christos output="-o $output"
200 1.1.1.6 christos error=`basename $OOPT .c`.error
201 1.1.1.6 christos else
202 1.1.1.6 christos error=${ROOT}${opt2}.error
203 1.1.1.6 christos fi
204 1.1.1.6 christos
205 1.1.1.6 christos $YACC $OPTS $opt2 -v -d $output $prefix -b $ROOT${opt2} $input 2>$error
206 1.1.1.5 christos for type in $TYPE
207 1.1.1.5 christos do
208 1.1.1.6 christos REF=${REF_DIR}/${root}${opt2}${type}
209 1.1.1.6 christos
210 1.1.1.6 christos # handle renaming due to "-o" option
211 1.1.1.6 christos if test -n "$OOPT"
212 1.1.1.5 christos then
213 1.1.1.6 christos case $type in
214 1.1.1.6 christos *.tab.c)
215 1.1.1.6 christos type=.c
216 1.1.1.6 christos ;;
217 1.1.1.6 christos *.tab.h)
218 1.1.1.6 christos type=.h
219 1.1.1.6 christos ;;
220 1.1.1.6 christos *)
221 1.1.1.6 christos ;;
222 1.1.1.6 christos esac
223 1.1.1.6 christos NEW=`basename $OOPT .c`${type}
224 1.1.1.6 christos case $NEW in
225 1.1.1.6 christos test-*)
226 1.1.1.6 christos ;;
227 1.1.1.6 christos *)
228 1.1.1.6 christos if test -f "$NEW"
229 1.1.1.6 christos then
230 1.1.1.6 christos REF=${REF_DIR}/$NEW
231 1.1.1.6 christos mv $NEW test-$NEW
232 1.1.1.6 christos NEW=test-$NEW
233 1.1.1.6 christos fi
234 1.1.1.6 christos ;;
235 1.1.1.6 christos esac
236 1.1.1.5 christos else
237 1.1.1.6 christos NEW=${ROOT}${opt2}${type}
238 1.1.1.5 christos fi
239 1.1.1.6 christos test_diffs
240 1.1.1.5 christos done
241 1.1 christos done
242 1.1 christos ;;
243 1.1 christos esac
244 1.1 christos done
245 1.1.1.6 christos
246 1.1.1.6 christos exit $errors
247