#!/bin/sh # $Id: run_test.sh,v 1.24 2014/07/15 19:21:10 tom Exp $ # vi:ts=4 sw=4: setglobal errors = '0' # NEW is the file created by the testcase # REF is the reference file against which to compare proc test_diffs { # echo "...test_diffs $NEW vs $REF" mv -f $NEW $(REF_DIR)/ setglobal CMP = "$(REF_DIR)/$(NEW)" if test ! -f $CMP { echo "...not found $CMP" setglobal errors = '1' } else { sed -e s,$NEW,$REF, \ -e "s%$YACC_escaped%YACC%" \ -e '/YYPATCH/s/[0-9][0-9]*/"yyyymmdd"/' \ -e '/#define YYPATCH/s/PATCH/CHECK/' \ -e 's,#line \([1-9][0-9]*\) "'$REF_DIR'/,#line \1 ",' \ -e 's,#line \([1-9][0-9]*\) "'$TEST_DIR'/,#line \1 ",' \ -e 's,\(YACC:.* line [0-9][0-9]* of "\)'$TEST_DIR/',\1./,' \ < $CMP >$tmpfile \ && mv $tmpfile $CMP if test ! -f $REF { mv $CMP $REF echo "...saved $REF" } elif shell { cmp -s $REF $CMP } { echo "...ok $REF" rm -f $CMP } else { echo "...diff $REF" diff -u $REF $CMP setglobal errors = '1' } } } proc test_flags { echo "** testing flags $ifsjoin(ARGV)" setglobal root = $1 setglobal ROOT = "test-$root" shift 1 $YACC $ifsjoin(ARGV) >$ROOT.output \ 2>&1 >$ROOT.error for type in [.output .error] { setglobal NEW = "$ROOT$type" setglobal REF = "$REF_DIR/$root$type" test_diffs } } if test $Argc = 1 { setglobal PROG_DIR = $[pwd] setglobal TEST_DIR = $1 setglobal PROG_DIR = $[echo $PROG_DIR | sed -e 's/ /\\\\ /g] setglobal TEST_DIR = $[echo $TEST_DIR | sed -e 's/ /\\\\ /g] } else { setglobal PROG_DIR = '..' setglobal TEST_DIR = '.' } setglobal YACC = "$PROG_DIR/yacc" setglobal YACC_escaped = $[echo "$PROG_DIR/yacc" | sed -e 's/\./\\\./g] setglobal tmpfile = "temp$Pid" setglobal ifBTYACC = $[fgrep -l 'define YYBTYACC' $PROG_DIR/config.h > /dev/null; test $Status != 0; echo $Status] if test $ifBTYACC = 0 { setglobal REF_DIR = "$(TEST_DIR)/yacc" } else { setglobal REF_DIR = "$(TEST_DIR)/btyacc" } rm -f $(REF_DIR)/test-* echo '** '$[date] # Tests which do not need files setglobal MYFILE = 'nosuchfile' test_flags help -z test_flags big_b -B test_flags big_l -L # Test attempts to read non-existent file rm -f $MYFILE.* test_flags nostdin - $MYFILE.y test_flags no_opts -- $MYFILE.y # Test attempts to write to readonly file touch $MYFILE.y touch $MYFILE.c chmod 444 $MYFILE.* test_flags no_b_opt -b test_flags no_b_opt1 -bBASE -o $MYFILE.c $MYFILE.y touch $MYFILE.c chmod 444 $MYFILE.* test_flags no_p_opt -p test_flags no_p_opt1 -pBASE -o $MYFILE.c $MYFILE.y rm -f BASE$MYFILE.c touch $MYFILE.dot chmod 444 $MYFILE.* test_flags no_graph -g -o $MYFILE.c $MYFILE.y rm -f $MYFILE.dot touch $MYFILE.output chmod 444 $MYFILE.* test_flags no_verbose -v -o $MYFILE.c $MYFILE.y test_flags no_output -o $MYFILE.output $MYFILE.y test_flags no_output1 -o$MYFILE.output $MYFILE.y test_flags no_output2 -o rm -f $MYFILE.output touch $MYFILE.h chmod 444 $MYFILE.* test_flags no_defines -d -o $MYFILE.c $MYFILE.y rm -f $MYFILE.h touch $MYFILE.i chmod 444 $MYFILE.* test_flags no_include -i -o $MYFILE.c $MYFILE.y rm -f $MYFILE.i touch $MYFILE.code.c chmod 444 $MYFILE.* test_flags no_code_c -r -o $MYFILE.c $MYFILE.y rm -f $MYFILE.code.c rm -f $MYFILE.* for input in [$(TEST_DIR)/*.y] { match $input { with test-* echo "?? ignored $input" with * setglobal root = $[basename $input .y] setglobal ROOT = ""test-$root"" setglobal prefix = "$(root)_" setglobal OPTS = '' setglobal OPT2 = '' setglobal OOPT = '' setglobal TYPE = '".error .output .tab.c .tab.h'" match $input { with ${TEST_DIR}/btyacc_* if test $ifBTYACC = 0 { continue; } setglobal OPTS = ""$OPTS -B"" setglobal prefix = $[echo $prefix | sed -e 's/^btyacc_//] with ${TEST_DIR}/grammar* setglobal OPTS = ""$OPTS -g"" setglobal TYPE = ""$TYPE .dot"" with ${TEST_DIR}/code_debug* setglobal OPTS = ""$OPTS -t -i"" setglobal OOPT = 'rename_debug.c' setglobal TYPE = ""$TYPE .i"" setglobal prefix = '' with ${TEST_DIR}/code_* setglobal OPTS = ""$OPTS -r"" setglobal TYPE = ""$TYPE .code.c"" setglobal prefix = $[echo $prefix | sed -e 's/^code_//] with ${TEST_DIR}/pure_* setglobal OPTS = ""$OPTS -P"" setglobal prefix = $[echo $prefix | sed -e 's/^pure_//] with ${TEST_DIR}/quote_* setglobal OPT2 = '"-s'" with ${TEST_DIR}/inherit*|\ ${TEST_DIR}/err_inherit* if test $ifBTYACC = 0 { continue; } } echo "** testing $input" test -n $prefix && setglobal prefix = ""-p $prefix"" for opt2 in ["" $OPT2] { setglobal output = $OOPT if test -n $output { setglobal output = ""-o $output"" setglobal error = "$[basename $OOPT .c].error" } else { setglobal error = "$(ROOT)$(opt2).error" } $YACC $OPTS $opt2 -v -d $output $prefix -b $ROOT$(opt2) $input 2>$error for type in [$TYPE] { setglobal REF = "$(REF_DIR)/$(root)$(opt2)$(type)" # handle renaming due to "-o" option if test -n $OOPT { match $type { with *.tab.c setglobal type = '.c' with *.tab.h setglobal type = '.h' with * } setglobal NEW = "$[basename $OOPT .c]$(type)" match $NEW { with test-* with * if test -f $NEW { setglobal REF = "$(REF_DIR)/$NEW" mv $NEW test-$NEW setglobal NEW = "test-$NEW" } } } else { setglobal NEW = "$(ROOT)$(opt2)$(type)" } test_diffs } } } } exit $errors