Home | History | Annotate | Line # | Download | only in test
run_test.sh revision 1.1.1.8.16.1
      1 #!/bin/sh
      2 # Id: run_test.sh,v 1.29 2019/06/17 08:12:47 tom Exp 
      3 # vi:ts=4 sw=4:
      4 
      5 errors=0
      6 
      7 # NEW is the file created by the testcase
      8 # REF is the reference file against which to compare
      9 test_diffs() {
     10 	# echo "...test_diffs $NEW vs $REF"
     11 	mv -f $NEW ${REF_DIR}/
     12 	CMP=${REF_DIR}/${NEW}
     13 	if test ! -f $CMP
     14 	then
     15 		echo "...not found $CMP"
     16 		errors=1
     17 	else
     18 		sed	-e s,$NEW,$REF, \
     19 			-e "s%$YACC_escaped%YACC%" \
     20 			-e '/YYPATCH/s/[0-9][0-9]*/"yyyymmdd"/' \
     21 			-e '/#define YYPATCH/s/PATCH/CHECK/' \
     22 			-e 's,#line \([1-9][0-9]*\) "'$REF_DIR'/,#line \1 ",' \
     23 			-e 's,#line \([1-9][0-9]*\) "'$TEST_DIR'/,#line \1 ",' \
     24 			-e 's,\(YACC:.* line [0-9][0-9]* of "\)'$TEST_DIR/',\1./,' \
     25 			< $CMP >$tmpfile \
     26 			&& mv $tmpfile $CMP
     27 		if test ! -f $REF
     28 		then
     29 			mv $CMP $REF
     30 			echo "...saved $REF"
     31 		elif ( cmp -s $REF $CMP )
     32 		then
     33 			echo "...ok $REF"
     34 			rm -f $CMP
     35 		else
     36 			echo "...diff $REF"
     37 			diff -u $REF $CMP
     38 			errors=1
     39 		fi
     40 	fi
     41 }
     42 
     43 test_flags() {
     44 	echo "** testing flags $*"
     45 	root=$1
     46 	ROOT=test-$root
     47 	shift 1
     48 	$YACC "$@" >$ROOT.output 2>$ROOT.error
     49 	for type in .output .error
     50 	do
     51 		NEW=$ROOT$type
     52 		REF=$REF_DIR/$root$type
     53 		test_diffs
     54 	done
     55 }
     56 
     57 test_stdin() {
     58 	echo "** testing stdin $*"
     59 	root=$1
     60 	ROOT=test-$root
     61 	shift 1
     62 	opts="$1"
     63 	shift 1
     64 	code=`echo "$1"|sed -e 's/y$/c/' -e "s,${TEST_DIR}/,,"`
     65 	if test "x$opts" = "x-"
     66 	then
     67 		$YACC -o $ROOT.$code $opts <$1 >$ROOT.output 2>$ROOT.error
     68 	else
     69 		$YACC -o $ROOT.$code $opts  $1 >$ROOT.output 2>$ROOT.error
     70 	fi
     71 	for type in .output .error .$code
     72 	do
     73 		NEW=$ROOT$type
     74 		REF=$REF_DIR/$root$type
     75 		test_diffs
     76 	done
     77 }
     78 
     79 test_defines() {
     80 	echo "** testing defines $*"
     81 	root=$1
     82 	ROOT=test-$root
     83 	shift 1
     84 	opts=
     85 	while test $# != 1
     86 	do
     87 		opts="$opts $1"
     88 		shift 1
     89 	done
     90 	head=`echo "$1"|sed -e 's/y$/h/' -e "s,${TEST_DIR}/,,"`
     91 	code=`echo "$1"|sed -e 's/y$/c/' -e "s,${TEST_DIR}/,,"`
     92 	$YACC $opts -H $ROOT.$head $1 >$ROOT.output 2>$ROOT.error
     93 	for name in prefix.tab.c y.tab.c
     94 	do
     95 		if test -f $name
     96 		then
     97 			mv $name $ROOT.$code
     98 			break
     99 		fi
    100 	done
    101 	for name in .output .error .$head .$code
    102 	do
    103 		NEW=$ROOT$name
    104 		REF=$REF_DIR/$root$name
    105 		test_diffs
    106 	done
    107 }
    108 
    109 if test $# = 1
    110 then
    111 	PROG_DIR=`pwd`
    112 	TEST_DIR=$1
    113 	PROG_DIR=`echo "$PROG_DIR" | sed -e 's/ /\\\\ /g'`
    114 	TEST_DIR=`echo "$TEST_DIR" | sed -e 's/ /\\\\ /g'`
    115 else
    116 	PROG_DIR=..
    117 	TEST_DIR=.
    118 fi
    119 
    120 YACC=$PROG_DIR/yacc
    121 YACC_escaped=`echo "$PROG_DIR/yacc" | sed -e 's/\./\\\./g'`
    122 
    123 tmpfile=temp$$
    124 
    125 ifBTYACC=`fgrep -l 'define YYBTYACC' $PROG_DIR/config.h > /dev/null; test $? != 0; echo $?`
    126 
    127 if test $ifBTYACC = 0; then
    128 	REF_DIR=${TEST_DIR}/yacc
    129 else
    130 	REF_DIR=${TEST_DIR}/btyacc
    131 fi
    132 
    133 rm -f ${REF_DIR}/test-*
    134 
    135 echo '** '`date`
    136 
    137 # Tests which do not need files
    138 MYFILE=nosuchfile
    139 test_flags help -z
    140 test_flags big_b -B
    141 test_flags big_l -L
    142 
    143 # Test attempts to read non-existent file
    144 rm -f $MYFILE.*
    145 test_flags nostdin - $MYFILE.y
    146 test_flags no_opts -- $MYFILE.y
    147 
    148 # Test attempts to write to readonly file
    149 touch $MYFILE.y
    150 
    151 touch $MYFILE.c
    152 chmod 444 $MYFILE.*
    153 test_flags no_b_opt   -b
    154 test_flags no_b_opt1  -bBASE -o $MYFILE.c $MYFILE.y
    155 
    156 touch $MYFILE.c
    157 chmod 444 $MYFILE.*
    158 test_flags no_p_opt   -p
    159 test_flags no_p_opt1  -pBASE -o $MYFILE.c $MYFILE.y
    160 rm -f BASE$MYFILE.c
    161 
    162 touch $MYFILE.dot
    163 chmod 444 $MYFILE.*
    164 test_flags no_graph   -g -o $MYFILE.c $MYFILE.y
    165 rm -f $MYFILE.dot
    166 
    167 touch $MYFILE.output
    168 chmod 444 $MYFILE.*
    169 test_flags no_verbose -v -o $MYFILE.c $MYFILE.y
    170 test_flags no_output  -o $MYFILE.output $MYFILE.y
    171 test_flags no_output1  -o$MYFILE.output $MYFILE.y
    172 test_flags no_output2  -o
    173 rm -f $MYFILE.output
    174 
    175 touch $MYFILE.h
    176 chmod 444 $MYFILE.*
    177 test_flags no_defines -d -o $MYFILE.c $MYFILE.y
    178 rm -f $MYFILE.h
    179 
    180 touch $MYFILE.i
    181 chmod 444 $MYFILE.*
    182 test_flags no_include -i -o $MYFILE.c $MYFILE.y
    183 rm -f $MYFILE.i
    184 
    185 touch $MYFILE.code.c
    186 chmod 444 $MYFILE.*
    187 test_flags no_code_c -r -o $MYFILE.c $MYFILE.y
    188 rm -f $MYFILE.code.c
    189 
    190 rm -f $MYFILE.*
    191 
    192 # Test special cases
    193 test_stdin stdin1 - ${TEST_DIR}/calc.y
    194 test_stdin stdin2 -- ${TEST_DIR}/calc.y
    195 
    196 test_defines defines1 ${TEST_DIR}/calc.y
    197 test_defines defines2 -d ${TEST_DIR}/calc.y
    198 test_defines defines3 -b prefix ${TEST_DIR}/calc.y
    199 
    200 for input in ${TEST_DIR}/*.y
    201 do
    202 	case $input in
    203 	test-*)
    204 		echo "?? ignored $input"
    205 		;;
    206 	*)
    207 		root=`basename $input .y`
    208 		ROOT="test-$root"
    209 		prefix=${root}_
    210 
    211 		OPTS=
    212 		OPT2=
    213 		OOPT=
    214 		TYPE=".error .output .tab.c .tab.h"
    215 		case $input in
    216 		${TEST_DIR}/btyacc_*)
    217 			if test $ifBTYACC = 0; then continue; fi
    218 			OPTS="$OPTS -B"
    219 			prefix=`echo "$prefix" | sed -e 's/^btyacc_//'`
    220 			;;
    221 		${TEST_DIR}/grammar*)
    222 			OPTS="$OPTS -g"
    223 			TYPE="$TYPE .dot"
    224 			;;
    225 		${TEST_DIR}/code_debug*)
    226 			OPTS="$OPTS -t -i"
    227 			OOPT=rename_debug.c
    228 			TYPE="$TYPE .i"
    229 			prefix=
    230 			;;
    231 		${TEST_DIR}/code_*)
    232 			OPTS="$OPTS -r"
    233 			TYPE="$TYPE .code.c"
    234 			prefix=`echo "$prefix" | sed -e 's/^code_//'`
    235 			;;
    236 		${TEST_DIR}/pure_*)
    237 			OPTS="$OPTS -P"
    238 			prefix=`echo "$prefix" | sed -e 's/^pure_//'`
    239 			;;
    240 		${TEST_DIR}/quote_*)
    241 			OPT2="-s"
    242 			;;
    243 		${TEST_DIR}/inherit*|\
    244 		${TEST_DIR}/err_inherit*)
    245 			if test $ifBTYACC = 0; then continue; fi
    246 			;;
    247 		esac
    248 
    249 		echo "** testing $input"
    250 
    251 		test -n "$prefix" && prefix="-p $prefix"
    252 
    253 		for opt2 in "" $OPT2
    254 		do
    255 			output=$OOPT
    256 			if test -n "$output"
    257 			then
    258 				output="-o $output"
    259 				error=`basename $OOPT .c`.error
    260 			else
    261 				error=${ROOT}${opt2}.error
    262 			fi
    263 
    264 			$YACC $OPTS $opt2 -v -d $output $prefix -b $ROOT${opt2} $input 2>$error
    265 			for type in $TYPE
    266 			do
    267 				REF=${REF_DIR}/${root}${opt2}${type}
    268 
    269 				# handle renaming due to "-o" option
    270 				if test -n "$OOPT"
    271 				then
    272 					case $type in
    273 					*.tab.c)
    274 						type=.c
    275 						;;
    276 					*.tab.h)
    277 						type=.h
    278 						;;
    279 					*)
    280 						;;
    281 					esac
    282 					NEW=`basename $OOPT .c`${type}
    283 					case $NEW in
    284 					test-*)
    285 						;;
    286 					*)
    287 						if test -f "$NEW"
    288 						then
    289 							REF=${REF_DIR}/$NEW
    290 							mv $NEW test-$NEW
    291 							NEW=test-$NEW
    292 						fi
    293 						;;
    294 					esac
    295 				else
    296 					NEW=${ROOT}${opt2}${type}
    297 				fi
    298 				test_diffs
    299 			done
    300 		done
    301 		;;
    302 	esac
    303 done
    304 
    305 exit $errors
    306