1#!/bin/sh 2# $Id: run_test.sh,v 1.22 2014/04/09 11:00:45 tom Exp $ 3# vi:ts=4 sw=4: 4 5# NEW is the file created by the testcase 6# REF is the reference file against which to compare 7test_diffs() { 8 # echo "...test_diffs $NEW vs $REF" 9 mv -f $NEW ${REF_DIR}/ 10 CMP=${REF_DIR}/${NEW} 11 if test ! -f $CMP 12 then 13 echo "...not found $CMP" 14 else 15 sed -e s,$NEW,$REF, \ 16 -e "s%$YACC%YACC%" \ 17 -e '/YYPATCH/s/[0-9][0-9]*/"yyyymmdd"/' \ 18 -e '/#define YYPATCH/s/PATCH/CHECK/' \ 19 -e 's,#line \([1-9][0-9]*\) "'$REF_DIR'/,#line \1 ",' \ 20 -e 's,#line \([1-9][0-9]*\) "'$TEST_DIR'/,#line \1 ",' \ 21 < $CMP >$tmpfile \ 22 && mv $tmpfile $CMP 23 if test ! -f $REF 24 then 25 mv $CMP $REF 26 echo "...saved $REF" 27 elif ( cmp -s $REF $CMP ) 28 then 29 echo "...ok $REF" 30 rm -f $CMP 31 else 32 echo "...diff $REF" 33 diff -u $REF $CMP 34 fi 35 fi 36} 37 38test_flags() { 39 echo "** testing flags $*" 40 root=$1 41 ROOT=test-$root 42 shift 1 43 $YACC $* >$ROOT.output \ 44 2>&1 >$ROOT.error 45 for type in .output .error 46 do 47 NEW=$ROOT$type 48 REF=$REF_DIR/$root$type 49 test_diffs 50 done 51} 52 53if test $# = 1 54then 55 PROG_DIR=`pwd` 56 TEST_DIR=$1 57 PROG_DIR=`echo "$PROG_DIR" | sed -e 's/ /\\\\ /g'` 58 TEST_DIR=`echo "$TEST_DIR" | sed -e 's/ /\\\\ /g'` 59else 60 PROG_DIR=.. 61 TEST_DIR=. 62fi 63 64YACC=$PROG_DIR/yacc 65 66tmpfile=temp$$ 67 68ifBTYACC=`fgrep -l 'define YYBTYACC' config.h > /dev/null; test $? != 0; echo $?` 69 70if test $ifBTYACC = 0; then 71 REF_DIR=${TEST_DIR}/yacc 72else 73 REF_DIR=${TEST_DIR}/btyacc 74fi 75 76rm -f ${REF_DIR}/test-* 77 78echo '** '`date` 79 80# Tests which do not need files 81MYFILE=nosuchfile 82test_flags help -z 83test_flags big_b -B 84test_flags big_l -L 85 86# Test attempts to read non-existent file 87rm -f $MYFILE.* 88test_flags nostdin - $MYFILE.y 89test_flags no_opts -- $MYFILE.y 90 91# Test attempts to write to readonly file 92touch $MYFILE.y 93 94touch $MYFILE.c 95chmod 444 $MYFILE.* 96test_flags no_b_opt -b 97test_flags no_b_opt1 -bBASE -o $MYFILE.c $MYFILE.y 98 99touch $MYFILE.c 100chmod 444 $MYFILE.* 101test_flags no_p_opt -p 102test_flags no_p_opt1 -pBASE -o $MYFILE.c $MYFILE.y 103rm -f BASE$MYFILE.c 104 105touch $MYFILE.dot 106chmod 444 $MYFILE.* 107test_flags no_graph -g -o $MYFILE.c $MYFILE.y 108rm -f $MYFILE.dot 109 110touch $MYFILE.output 111chmod 444 $MYFILE.* 112test_flags no_verbose -v -o $MYFILE.c $MYFILE.y 113test_flags no_output -o $MYFILE.output $MYFILE.y 114test_flags no_output1 -o$MYFILE.output $MYFILE.y 115test_flags no_output2 -o 116rm -f $MYFILE.output 117 118touch $MYFILE.h 119chmod 444 $MYFILE.* 120test_flags no_defines -d -o $MYFILE.c $MYFILE.y 121rm -f $MYFILE.h 122 123touch $MYFILE.i 124chmod 444 $MYFILE.* 125test_flags no_include -i -o $MYFILE.c $MYFILE.y 126rm -f $MYFILE.i 127 128touch $MYFILE.code.c 129chmod 444 $MYFILE.* 130test_flags no_code_c -r -o $MYFILE.c $MYFILE.y 131rm -f $MYFILE.code.c 132 133rm -f $MYFILE.* 134 135for input in ${TEST_DIR}/*.y 136do 137 case $input in 138 test-*) 139 echo "?? ignored $input" 140 ;; 141 *) 142 root=`basename $input .y` 143 ROOT="test-$root" 144 prefix=${root}_ 145 146 OPTS= 147 OPT2= 148 OOPT= 149 TYPE=".error .output .tab.c .tab.h" 150 case $input in 151 ${TEST_DIR}/btyacc_*) 152 if test $ifBTYACC = 0; then continue; fi 153 OPTS="$OPTS -B" 154 prefix=`echo "$prefix" | sed -e 's/^btyacc_//'` 155 ;; 156 ${TEST_DIR}/grammar*) 157 OPTS="$OPTS -g" 158 TYPE="$TYPE .dot" 159 ;; 160 ${TEST_DIR}/code_debug*) 161 OPTS="$OPTS -t -i" 162 OOPT=rename_debug.c 163 TYPE="$TYPE .i" 164 prefix= 165 ;; 166 ${TEST_DIR}/code_*) 167 OPTS="$OPTS -r" 168 TYPE="$TYPE .code.c" 169 prefix=`echo "$prefix" | sed -e 's/^code_//'` 170 ;; 171 ${TEST_DIR}/pure_*) 172 OPTS="$OPTS -P" 173 prefix=`echo "$prefix" | sed -e 's/^pure_//'` 174 ;; 175 ${TEST_DIR}/quote_*) 176 OPT2="-s" 177 ;; 178 ${TEST_DIR}/inherit*|\ 179 ${TEST_DIR}/err_inherit*) 180 if test $ifBTYACC = 0; then continue; fi 181 ;; 182 esac 183 184 echo "** testing $input" 185 186 test -n "$prefix" && prefix="-p $prefix" 187 188 for opt2 in "" $OPT2 189 do 190 output=$OOPT 191 if test -n "$output" 192 then 193 output="-o $output" 194 error=`basename $OOPT .c`.error 195 else 196 error=${ROOT}${opt2}.error 197 fi 198 199 $YACC $OPTS $opt2 -v -d $output $prefix -b $ROOT${opt2} $input 2>$error 200 for type in $TYPE 201 do 202 REF=${REF_DIR}/${root}${opt2}${type} 203 204 # handle renaming due to "-o" option 205 if test -n "$OOPT" 206 then 207 case $type in 208 *.tab.c) 209 type=.c 210 ;; 211 *.tab.h) 212 type=.h 213 ;; 214 *) 215 ;; 216 esac 217 NEW=`basename $OOPT .c`${type} 218 case $NEW in 219 test-*) 220 ;; 221 *) 222 if test -f "$NEW" 223 then 224 REF=${REF_DIR}/$NEW 225 mv $NEW test-$NEW 226 NEW=test-$NEW 227 fi 228 ;; 229 esac 230 else 231 NEW=${ROOT}${opt2}${type} 232 fi 233 test_diffs 234 done 235 done 236 ;; 237 esac 238done 239