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