2 # $Id: run_test.sh,v 1.37 2022/11/06 21:55:25 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 : "${FGREP:=grep -F}"
131 ifBTYACC=`$FGREP -l 'define YYBTYACC' $PROG_DIR/config.h > /dev/null; test $? != 0; echo $?`
133 if test "$ifBTYACC" = 0; then
134 REF_DIR=${TEST_DIR}/yacc
136 REF_DIR=${TEST_DIR}/btyacc
139 rm -f ${REF_DIR}/test-*
143 # Tests which do not need files
149 # Test attempts to read non-existent file
151 test_flags nostdin - $MYFILE.y
152 test_flags no_opts -- $MYFILE.y
154 # Test attempts to write to readonly file
159 test_flags no_b_opt -b
160 test_flags no_b_opt1 -bBASE -o $MYFILE.c $MYFILE.y
164 test_flags no_p_opt -p
165 test_flags no_p_opt1 -pBASE -o $MYFILE.c $MYFILE.y
170 test_flags no_graph -g -o $MYFILE.c $MYFILE.y
175 test_flags no_verbose -v -o $MYFILE.c $MYFILE.y
176 test_flags no_output -o $MYFILE.output $MYFILE.y
177 test_flags no_output1 -o$MYFILE.output $MYFILE.y
178 test_flags no_output2 -o
183 test_flags no_defines -d -o $MYFILE.c $MYFILE.y
188 test_flags no_include -i -o $MYFILE.c $MYFILE.y
193 test_flags no_code_c -r -o $MYFILE.c $MYFILE.y
199 test_stdin stdin1 - ${TEST_DIR}/calc.y
200 test_stdin stdin2 -- ${TEST_DIR}/calc.y
202 test_defines defines1 ${TEST_DIR}/calc.y
203 test_defines defines2 -d ${TEST_DIR}/calc.y
204 test_defines defines3 -b prefix ${TEST_DIR}/calc.y
206 for input in "${TEST_DIR}"/*.y
210 echo "?? ignored $input"
213 root=`basename "$input" .y`
215 prefix=`echo "${root}_" | sed -e 's/[.]/_/g'`
220 TYPE=".error .output .tab.c .tab.h"
222 ${TEST_DIR}/btyacc_*)
223 if test "$ifBTYACC" = 0; then continue; fi
225 prefix=`echo "$prefix" | sed -e 's/^btyacc_//'`
227 ${TEST_DIR}/grammar*)
231 ${TEST_DIR}/code_debug*)
240 prefix=`echo "$prefix" | sed -e 's/^code_//'`
244 prefix=`echo "$prefix" | sed -e 's/^pure_//'`
249 ${TEST_DIR}/inherit*|\
250 ${TEST_DIR}/err_inherit*)
251 if test "$ifBTYACC" = 0; then continue; fi
255 echo "** testing $input"
257 test -n "$prefix" && prefix="-p $prefix"
265 error=`basename "$OOPT" .c`.error
267 error=${ROOT}${opt2}.error
270 $YACC $OPTS $opt2 -v -d $output $prefix -b "$ROOT${opt2}" "$input" 2>"$error"
273 REF=${REF_DIR}/${root}${opt2}${type}
275 # handle renaming due to "-o" option
288 NEW=`basename "$OOPT" .c`${type}
296 mv "$NEW" "test-$NEW"
302 NEW="${ROOT}${opt2}${type}"