2 # $Id: run_test.sh,v 1.35 2022/01/01 22:28:17 tom Exp $
7 # NEW is the file created by the testcase
8 # REF is the reference file against which to compare
10 # echo "...test_diffs $NEW vs $REF"
11 mv -f "$NEW" "${REF_DIR}/"
15 echo "...not found $CMP"
18 sed -e "s,$NEW,$REF," \
19 -e "s%$YACC_escaped%YACC%" \
20 -e "s%^yacc\>%YACC%" \
21 -e "s%YACC:.*option.*$%YACC: error message%" \
22 -e "s%yacc:.*option.*$%YACC: error message%" \
23 -e "s%^Usage: yacc\>%Usage: YACC%" \
24 -e '/YYPATCH/s/[0-9][0-9]*/"yyyymmdd"/' \
25 -e '/#define YYPATCH/s/PATCH/CHECK/' \
26 -e 's,#line \([1-9][0-9]*\) "'"$REF_DIR"'/,#line \1 ",' \
27 -e 's,#line \([1-9][0-9]*\) "'"$TEST_DIR"'/,#line \1 ",' \
28 -e 's/^typedef \(short\|long\) YYINT;$/typedef int YYINT;/' \
29 -e 's,\(YACC:.* line [0-9][0-9]* of "\)'"$TEST_DIR/"',\1./,' \
30 < "$CMP" >"$tmpfile" \
31 && mv "$tmpfile" "$CMP"
36 elif ( cmp -s "$REF" "$CMP" )
49 echo "** testing flags $*"
53 $YACC "$@" >"$ROOT.output" 2>"$ROOT.error"
54 for type in .output .error
57 REF=$REF_DIR/$root$type
63 echo "** testing stdin $*"
69 code=`echo "$1"|sed -e 's/y$/c/' -e "s,${TEST_DIR}/,,"`
70 if test "x$opts" = "x-"
72 $YACC -o "$ROOT.$code" $opts <$1 >"$ROOT.output" 2>"$ROOT.error"
74 $YACC -o "$ROOT.$code" $opts $1 >"$ROOT.output" 2>"$ROOT.error"
76 for type in .output .error .$code
79 REF=$REF_DIR/$root$type
85 echo "** testing defines $*"
95 head=`echo "$1"|sed -e 's/y$/h/' -e "s,${TEST_DIR}/,,"`
96 code=`echo "$1"|sed -e 's/y$/c/' -e "s,${TEST_DIR}/,,"`
97 $YACC $opts -H "$ROOT.$head" $1 >"$ROOT.output" 2>"$ROOT.error"
98 for name in prefix.tab.c y.tab.c
102 mv "$name" "$ROOT.$code"
106 for name in .output .error .$head .$code
109 REF=$REF_DIR/$root$name
118 PROG_DIR=`echo "$PROG_DIR" | sed -e 's/ /\\\\ /g'`
119 TEST_DIR=`echo "$TEST_DIR" | sed -e 's/ /\\\\ /g'`
126 YACC_escaped=`echo "$PROG_DIR/yacc" | sed -e 's/\./\\\./g'`
130 ifBTYACC=`grep -F -l 'define YYBTYACC' $PROG_DIR/config.h > /dev/null; test $? != 0; echo $?`
132 if test "$ifBTYACC" = 0; then
133 REF_DIR=${TEST_DIR}/yacc
135 REF_DIR=${TEST_DIR}/btyacc
138 rm -f ${REF_DIR}/test-*
142 # Tests which do not need files
148 # Test attempts to read non-existent file
150 test_flags nostdin - $MYFILE.y
151 test_flags no_opts -- $MYFILE.y
153 # Test attempts to write to readonly file
158 test_flags no_b_opt -b
159 test_flags no_b_opt1 -bBASE -o $MYFILE.c $MYFILE.y
163 test_flags no_p_opt -p
164 test_flags no_p_opt1 -pBASE -o $MYFILE.c $MYFILE.y
169 test_flags no_graph -g -o $MYFILE.c $MYFILE.y
174 test_flags no_verbose -v -o $MYFILE.c $MYFILE.y
175 test_flags no_output -o $MYFILE.output $MYFILE.y
176 test_flags no_output1 -o$MYFILE.output $MYFILE.y
177 test_flags no_output2 -o
182 test_flags no_defines -d -o $MYFILE.c $MYFILE.y
187 test_flags no_include -i -o $MYFILE.c $MYFILE.y
192 test_flags no_code_c -r -o $MYFILE.c $MYFILE.y
198 test_stdin stdin1 - ${TEST_DIR}/calc.y
199 test_stdin stdin2 -- ${TEST_DIR}/calc.y
201 test_defines defines1 ${TEST_DIR}/calc.y
202 test_defines defines2 -d ${TEST_DIR}/calc.y
203 test_defines defines3 -b prefix ${TEST_DIR}/calc.y
205 for input in "${TEST_DIR}"/*.y
209 echo "?? ignored $input"
212 root=`basename "$input" .y`
214 prefix=`echo "${root}_" | sed -e 's/[.]/_/g'`
219 TYPE=".error .output .tab.c .tab.h"
221 ${TEST_DIR}/btyacc_*)
222 if test "$ifBTYACC" = 0; then continue; fi
224 prefix=`echo "$prefix" | sed -e 's/^btyacc_//'`
226 ${TEST_DIR}/grammar*)
230 ${TEST_DIR}/code_debug*)
239 prefix=`echo "$prefix" | sed -e 's/^code_//'`
243 prefix=`echo "$prefix" | sed -e 's/^pure_//'`
248 ${TEST_DIR}/inherit*|\
249 ${TEST_DIR}/err_inherit*)
250 if test "$ifBTYACC" = 0; then continue; fi
254 echo "** testing $input"
256 test -n "$prefix" && prefix="-p $prefix"
264 error=`basename "$OOPT" .c`.error
266 error=${ROOT}${opt2}.error
269 $YACC $OPTS $opt2 -v -d $output $prefix -b "$ROOT${opt2}" "$input" 2>"$error"
272 REF=${REF_DIR}/${root}${opt2}${type}
274 # handle renaming due to "-o" option
287 NEW=`basename "$OOPT" .c`${type}
295 mv "$NEW" "test-$NEW"
301 NEW="${ROOT}${opt2}${type}"