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