run_test.sh revision 264803
1234949Sbapt#!/bin/sh 2264803Sbapt# $Id: run_test.sh,v 1.22 2014/04/09 11:00:45 tom Exp $ 3234949Sbapt# vi:ts=4 sw=4: 4234949Sbapt 5264803Sbapt# NEW is the file created by the testcase 6264803Sbapt# REF is the reference file against which to compare 7264803Sbapttest_diffs() { 8264803Sbapt # echo "...test_diffs $NEW vs $REF" 9264803Sbapt mv -f $NEW ${REF_DIR}/ 10264803Sbapt CMP=${REF_DIR}/${NEW} 11264803Sbapt if test ! -f $CMP 12264803Sbapt then 13264803Sbapt echo "...not found $CMP" 14264803Sbapt else 15264803Sbapt sed -e s,$NEW,$REF, \ 16264803Sbapt -e "s%$YACC%YACC%" \ 17264803Sbapt -e '/YYPATCH/s/[0-9][0-9]*/"yyyymmdd"/' \ 18264803Sbapt -e '/#define YYPATCH/s/PATCH/CHECK/' \ 19264803Sbapt -e 's,#line \([1-9][0-9]*\) "'$REF_DIR'/,#line \1 ",' \ 20264803Sbapt -e 's,#line \([1-9][0-9]*\) "'$TEST_DIR'/,#line \1 ",' \ 21264803Sbapt < $CMP >$tmpfile \ 22264803Sbapt && mv $tmpfile $CMP 23264803Sbapt if test ! -f $REF 24264803Sbapt then 25264803Sbapt mv $CMP $REF 26264803Sbapt echo "...saved $REF" 27264803Sbapt elif ( cmp -s $REF $CMP ) 28264803Sbapt then 29264803Sbapt echo "...ok $REF" 30264803Sbapt rm -f $CMP 31264803Sbapt else 32264803Sbapt echo "...diff $REF" 33264803Sbapt diff -u $REF $CMP 34264803Sbapt fi 35264803Sbapt fi 36264803Sbapt} 37264803Sbapt 38264803Sbapttest_flags() { 39264803Sbapt echo "** testing flags $*" 40264803Sbapt root=$1 41264803Sbapt ROOT=test-$root 42264803Sbapt shift 1 43264803Sbapt $YACC $* >$ROOT.output \ 44264803Sbapt 2>&1 >$ROOT.error 45264803Sbapt for type in .output .error 46264803Sbapt do 47264803Sbapt NEW=$ROOT$type 48264803Sbapt REF=$REF_DIR/$root$type 49264803Sbapt test_diffs 50264803Sbapt done 51264803Sbapt} 52264803Sbapt 53234949Sbaptif test $# = 1 54234949Sbaptthen 55234949Sbapt PROG_DIR=`pwd` 56234949Sbapt TEST_DIR=$1 57264803Sbapt PROG_DIR=`echo "$PROG_DIR" | sed -e 's/ /\\\\ /g'` 58264803Sbapt TEST_DIR=`echo "$TEST_DIR" | sed -e 's/ /\\\\ /g'` 59234949Sbaptelse 60234949Sbapt PROG_DIR=.. 61234949Sbapt TEST_DIR=. 62234949Sbaptfi 63234949Sbapt 64234949SbaptYACC=$PROG_DIR/yacc 65234949Sbapt 66234949Sbapttmpfile=temp$$ 67234949Sbapt 68264803SbaptifBTYACC=`fgrep -l 'define YYBTYACC' config.h > /dev/null; test $? != 0; echo $?` 69264803Sbapt 70264803Sbaptif test $ifBTYACC = 0; then 71264803Sbapt REF_DIR=${TEST_DIR}/yacc 72264803Sbaptelse 73264803Sbapt REF_DIR=${TEST_DIR}/btyacc 74264803Sbaptfi 75264803Sbapt 76264803Sbaptrm -f ${REF_DIR}/test-* 77264803Sbapt 78234949Sbaptecho '** '`date` 79264803Sbapt 80264803Sbapt# Tests which do not need files 81264803SbaptMYFILE=nosuchfile 82264803Sbapttest_flags help -z 83264803Sbapttest_flags big_b -B 84264803Sbapttest_flags big_l -L 85264803Sbapt 86264803Sbapt# Test attempts to read non-existent file 87264803Sbaptrm -f $MYFILE.* 88264803Sbapttest_flags nostdin - $MYFILE.y 89264803Sbapttest_flags no_opts -- $MYFILE.y 90264803Sbapt 91264803Sbapt# Test attempts to write to readonly file 92264803Sbapttouch $MYFILE.y 93264803Sbapt 94264803Sbapttouch $MYFILE.c 95264803Sbaptchmod 444 $MYFILE.* 96264803Sbapttest_flags no_b_opt -b 97264803Sbapttest_flags no_b_opt1 -bBASE -o $MYFILE.c $MYFILE.y 98264803Sbapt 99264803Sbapttouch $MYFILE.c 100264803Sbaptchmod 444 $MYFILE.* 101264803Sbapttest_flags no_p_opt -p 102264803Sbapttest_flags no_p_opt1 -pBASE -o $MYFILE.c $MYFILE.y 103264803Sbaptrm -f BASE$MYFILE.c 104264803Sbapt 105264803Sbapttouch $MYFILE.dot 106264803Sbaptchmod 444 $MYFILE.* 107264803Sbapttest_flags no_graph -g -o $MYFILE.c $MYFILE.y 108264803Sbaptrm -f $MYFILE.dot 109264803Sbapt 110264803Sbapttouch $MYFILE.output 111264803Sbaptchmod 444 $MYFILE.* 112264803Sbapttest_flags no_verbose -v -o $MYFILE.c $MYFILE.y 113264803Sbapttest_flags no_output -o $MYFILE.output $MYFILE.y 114264803Sbapttest_flags no_output1 -o$MYFILE.output $MYFILE.y 115264803Sbapttest_flags no_output2 -o 116264803Sbaptrm -f $MYFILE.output 117264803Sbapt 118264803Sbapttouch $MYFILE.h 119264803Sbaptchmod 444 $MYFILE.* 120264803Sbapttest_flags no_defines -d -o $MYFILE.c $MYFILE.y 121264803Sbaptrm -f $MYFILE.h 122264803Sbapt 123264803Sbapttouch $MYFILE.i 124264803Sbaptchmod 444 $MYFILE.* 125264803Sbapttest_flags no_include -i -o $MYFILE.c $MYFILE.y 126264803Sbaptrm -f $MYFILE.i 127264803Sbapt 128264803Sbapttouch $MYFILE.code.c 129264803Sbaptchmod 444 $MYFILE.* 130264803Sbapttest_flags no_code_c -r -o $MYFILE.c $MYFILE.y 131264803Sbaptrm -f $MYFILE.code.c 132264803Sbapt 133264803Sbaptrm -f $MYFILE.* 134264803Sbapt 135234949Sbaptfor input in ${TEST_DIR}/*.y 136234949Sbaptdo 137234949Sbapt case $input in 138264803Sbapt test-*) 139234949Sbapt echo "?? ignored $input" 140234949Sbapt ;; 141234949Sbapt *) 142234949Sbapt root=`basename $input .y` 143234949Sbapt ROOT="test-$root" 144234949Sbapt prefix=${root}_ 145234949Sbapt 146234949Sbapt OPTS= 147234949Sbapt OPT2= 148264803Sbapt OOPT= 149264803Sbapt TYPE=".error .output .tab.c .tab.h" 150234949Sbapt case $input in 151264803Sbapt ${TEST_DIR}/btyacc_*) 152264803Sbapt if test $ifBTYACC = 0; then continue; fi 153264803Sbapt OPTS="$OPTS -B" 154264803Sbapt prefix=`echo "$prefix" | sed -e 's/^btyacc_//'` 155264803Sbapt ;; 156264803Sbapt ${TEST_DIR}/grammar*) 157264803Sbapt OPTS="$OPTS -g" 158264803Sbapt TYPE="$TYPE .dot" 159264803Sbapt ;; 160264803Sbapt ${TEST_DIR}/code_debug*) 161264803Sbapt OPTS="$OPTS -t -i" 162264803Sbapt OOPT=rename_debug.c 163264803Sbapt TYPE="$TYPE .i" 164264803Sbapt prefix= 165264803Sbapt ;; 166234949Sbapt ${TEST_DIR}/code_*) 167234949Sbapt OPTS="$OPTS -r" 168234949Sbapt TYPE="$TYPE .code.c" 169234949Sbapt prefix=`echo "$prefix" | sed -e 's/^code_//'` 170234949Sbapt ;; 171234949Sbapt ${TEST_DIR}/pure_*) 172234949Sbapt OPTS="$OPTS -P" 173234949Sbapt prefix=`echo "$prefix" | sed -e 's/^pure_//'` 174234949Sbapt ;; 175234949Sbapt ${TEST_DIR}/quote_*) 176234949Sbapt OPT2="-s" 177234949Sbapt ;; 178264803Sbapt ${TEST_DIR}/inherit*|\ 179264803Sbapt ${TEST_DIR}/err_inherit*) 180264803Sbapt if test $ifBTYACC = 0; then continue; fi 181264803Sbapt ;; 182234949Sbapt esac 183234949Sbapt 184264803Sbapt echo "** testing $input" 185264803Sbapt 186264803Sbapt test -n "$prefix" && prefix="-p $prefix" 187264803Sbapt 188234949Sbapt for opt2 in "" $OPT2 189234949Sbapt do 190264803Sbapt output=$OOPT 191264803Sbapt if test -n "$output" 192264803Sbapt then 193264803Sbapt output="-o $output" 194264803Sbapt error=`basename $OOPT .c`.error 195264803Sbapt else 196264803Sbapt error=${ROOT}${opt2}.error 197264803Sbapt fi 198264803Sbapt 199264803Sbapt $YACC $OPTS $opt2 -v -d $output $prefix -b $ROOT${opt2} $input 2>$error 200234949Sbapt for type in $TYPE 201234949Sbapt do 202264803Sbapt REF=${REF_DIR}/${root}${opt2}${type} 203264803Sbapt 204264803Sbapt # handle renaming due to "-o" option 205264803Sbapt if test -n "$OOPT" 206234949Sbapt then 207264803Sbapt case $type in 208264803Sbapt *.tab.c) 209264803Sbapt type=.c 210264803Sbapt ;; 211264803Sbapt *.tab.h) 212264803Sbapt type=.h 213264803Sbapt ;; 214264803Sbapt *) 215264803Sbapt ;; 216264803Sbapt esac 217264803Sbapt NEW=`basename $OOPT .c`${type} 218264803Sbapt case $NEW in 219264803Sbapt test-*) 220264803Sbapt ;; 221264803Sbapt *) 222264803Sbapt if test -f "$NEW" 223264803Sbapt then 224264803Sbapt REF=${REF_DIR}/$NEW 225264803Sbapt mv $NEW test-$NEW 226264803Sbapt NEW=test-$NEW 227264803Sbapt fi 228264803Sbapt ;; 229264803Sbapt esac 230234949Sbapt else 231264803Sbapt NEW=${ROOT}${opt2}${type} 232234949Sbapt fi 233264803Sbapt test_diffs 234234949Sbapt done 235234949Sbapt done 236234949Sbapt ;; 237234949Sbapt esac 238234949Sbaptdone 239