Home | History | Annotate | Line # | Download | only in test
run_test.sh revision 1.1.1.7
      1 #!/bin/sh
      2 # $Id: run_test.sh,v 1.1.1.7 2016/01/09 21:55:11 christos 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 \
     49 	    2>&1 >$ROOT.error
     50 	for type in .output .error
     51 	do
     52 		NEW=$ROOT$type
     53 		REF=$REF_DIR/$root$type
     54 		test_diffs
     55 	done
     56 }
     57 
     58 if test $# = 1
     59 then
     60 	PROG_DIR=`pwd`
     61 	TEST_DIR=$1
     62 	PROG_DIR=`echo "$PROG_DIR" | sed -e 's/ /\\\\ /g'`
     63 	TEST_DIR=`echo "$TEST_DIR" | sed -e 's/ /\\\\ /g'`
     64 else
     65 	PROG_DIR=..
     66 	TEST_DIR=.
     67 fi
     68 
     69 YACC=$PROG_DIR/yacc
     70 YACC_escaped=`echo "$PROG_DIR/yacc" | sed -e 's/\./\\\./g'`
     71 
     72 tmpfile=temp$$
     73 
     74 ifBTYACC=`fgrep -l 'define YYBTYACC' $PROG_DIR/config.h > /dev/null; test $? != 0; echo $?`
     75 
     76 if test $ifBTYACC = 0; then
     77 	REF_DIR=${TEST_DIR}/yacc
     78 else
     79 	REF_DIR=${TEST_DIR}/btyacc
     80 fi
     81 
     82 rm -f ${REF_DIR}/test-*
     83 
     84 echo '** '`date`
     85 
     86 # Tests which do not need files
     87 MYFILE=nosuchfile
     88 test_flags help -z
     89 test_flags big_b -B
     90 test_flags big_l -L
     91 
     92 # Test attempts to read non-existent file
     93 rm -f $MYFILE.*
     94 test_flags nostdin - $MYFILE.y
     95 test_flags no_opts -- $MYFILE.y
     96 
     97 # Test attempts to write to readonly file
     98 touch $MYFILE.y
     99 
    100 touch $MYFILE.c
    101 chmod 444 $MYFILE.*
    102 test_flags no_b_opt   -b
    103 test_flags no_b_opt1  -bBASE -o $MYFILE.c $MYFILE.y
    104 
    105 touch $MYFILE.c
    106 chmod 444 $MYFILE.*
    107 test_flags no_p_opt   -p
    108 test_flags no_p_opt1  -pBASE -o $MYFILE.c $MYFILE.y
    109 rm -f BASE$MYFILE.c
    110 
    111 touch $MYFILE.dot
    112 chmod 444 $MYFILE.*
    113 test_flags no_graph   -g -o $MYFILE.c $MYFILE.y
    114 rm -f $MYFILE.dot
    115 
    116 touch $MYFILE.output
    117 chmod 444 $MYFILE.*
    118 test_flags no_verbose -v -o $MYFILE.c $MYFILE.y
    119 test_flags no_output  -o $MYFILE.output $MYFILE.y
    120 test_flags no_output1  -o$MYFILE.output $MYFILE.y
    121 test_flags no_output2  -o
    122 rm -f $MYFILE.output
    123 
    124 touch $MYFILE.h
    125 chmod 444 $MYFILE.*
    126 test_flags no_defines -d -o $MYFILE.c $MYFILE.y
    127 rm -f $MYFILE.h
    128 
    129 touch $MYFILE.i
    130 chmod 444 $MYFILE.*
    131 test_flags no_include -i -o $MYFILE.c $MYFILE.y
    132 rm -f $MYFILE.i
    133 
    134 touch $MYFILE.code.c
    135 chmod 444 $MYFILE.*
    136 test_flags no_code_c -r -o $MYFILE.c $MYFILE.y
    137 rm -f $MYFILE.code.c
    138 
    139 rm -f $MYFILE.*
    140 
    141 for input in ${TEST_DIR}/*.y
    142 do
    143 	case $input in
    144 	test-*)
    145 		echo "?? ignored $input"
    146 		;;
    147 	*)
    148 		root=`basename $input .y`
    149 		ROOT="test-$root"
    150 		prefix=${root}_
    151 
    152 		OPTS=
    153 		OPT2=
    154 		OOPT=
    155 		TYPE=".error .output .tab.c .tab.h"
    156 		case $input in
    157 		${TEST_DIR}/btyacc_*)
    158 			if test $ifBTYACC = 0; then continue; fi
    159 			OPTS="$OPTS -B"
    160 			prefix=`echo "$prefix" | sed -e 's/^btyacc_//'`
    161 			;;
    162 		${TEST_DIR}/grammar*)
    163 			OPTS="$OPTS -g"
    164 			TYPE="$TYPE .dot"
    165 			;;
    166 		${TEST_DIR}/code_debug*)
    167 			OPTS="$OPTS -t -i"
    168 			OOPT=rename_debug.c
    169 			TYPE="$TYPE .i"
    170 			prefix=
    171 			;;
    172 		${TEST_DIR}/code_*)
    173 			OPTS="$OPTS -r"
    174 			TYPE="$TYPE .code.c"
    175 			prefix=`echo "$prefix" | sed -e 's/^code_//'`
    176 			;;
    177 		${TEST_DIR}/pure_*)
    178 			OPTS="$OPTS -P"
    179 			prefix=`echo "$prefix" | sed -e 's/^pure_//'`
    180 			;;
    181 		${TEST_DIR}/quote_*)
    182 			OPT2="-s"
    183 			;;
    184 		${TEST_DIR}/inherit*|\
    185 		${TEST_DIR}/err_inherit*)
    186 			if test $ifBTYACC = 0; then continue; fi
    187 			;;
    188 		esac
    189 
    190 		echo "** testing $input"
    191 
    192 		test -n "$prefix" && prefix="-p $prefix"
    193 
    194 		for opt2 in "" $OPT2
    195 		do
    196 			output=$OOPT
    197 			if test -n "$output"
    198 			then
    199 				output="-o $output"
    200 				error=`basename $OOPT .c`.error
    201 			else
    202 				error=${ROOT}${opt2}.error
    203 			fi
    204 
    205 			$YACC $OPTS $opt2 -v -d $output $prefix -b $ROOT${opt2} $input 2>$error
    206 			for type in $TYPE
    207 			do
    208 				REF=${REF_DIR}/${root}${opt2}${type}
    209 
    210 				# handle renaming due to "-o" option
    211 				if test -n "$OOPT"
    212 				then
    213 					case $type in
    214 					*.tab.c)
    215 						type=.c
    216 						;;
    217 					*.tab.h)
    218 						type=.h
    219 						;;
    220 					*)
    221 						;;
    222 					esac
    223 					NEW=`basename $OOPT .c`${type}
    224 					case $NEW in
    225 					test-*)
    226 						;;
    227 					*)
    228 						if test -f "$NEW"
    229 						then
    230 							REF=${REF_DIR}/$NEW
    231 							mv $NEW test-$NEW
    232 							NEW=test-$NEW
    233 						fi
    234 						;;
    235 					esac
    236 				else
    237 					NEW=${ROOT}${opt2}${type}
    238 				fi
    239 				test_diffs
    240 			done
    241 		done
    242 		;;
    243 	esac
    244 done
    245 
    246 exit $errors
    247