xref: /freebsd/contrib/byacc/test/run_test.sh (revision bb9eb45ab44e045c941b22df7090b56fc3f769df)
198e903e7SBaptiste Daroussin#!/bin/sh
2*bb9eb45aSBaptiste Daroussin# $Id: run_test.sh,v 1.24 2014/07/15 19:21:10 tom Exp $
398e903e7SBaptiste Daroussin# vi:ts=4 sw=4:
498e903e7SBaptiste Daroussin
5*bb9eb45aSBaptiste Daroussinerrors=0
6*bb9eb45aSBaptiste Daroussin
70c8de5b0SBaptiste Daroussin# NEW is the file created by the testcase
80c8de5b0SBaptiste Daroussin# REF is the reference file against which to compare
90c8de5b0SBaptiste Daroussintest_diffs() {
100c8de5b0SBaptiste Daroussin	# echo "...test_diffs $NEW vs $REF"
110c8de5b0SBaptiste Daroussin	mv -f $NEW ${REF_DIR}/
120c8de5b0SBaptiste Daroussin	CMP=${REF_DIR}/${NEW}
1398e903e7SBaptiste Daroussin	if test ! -f $CMP
1498e903e7SBaptiste Daroussin	then
1598e903e7SBaptiste Daroussin		echo "...not found $CMP"
16*bb9eb45aSBaptiste Daroussin		errors=1
1798e903e7SBaptiste Daroussin	else
180c8de5b0SBaptiste Daroussin		sed	-e s,$NEW,$REF, \
19*bb9eb45aSBaptiste Daroussin			-e "s%$YACC_escaped%YACC%" \
200c8de5b0SBaptiste Daroussin			-e '/YYPATCH/s/[0-9][0-9]*/"yyyymmdd"/' \
210c8de5b0SBaptiste Daroussin			-e '/#define YYPATCH/s/PATCH/CHECK/' \
220c8de5b0SBaptiste Daroussin			-e 's,#line \([1-9][0-9]*\) "'$REF_DIR'/,#line \1 ",' \
2398e903e7SBaptiste Daroussin			-e 's,#line \([1-9][0-9]*\) "'$TEST_DIR'/,#line \1 ",' \
24*bb9eb45aSBaptiste Daroussin			-e 's,\(YACC:.* line [0-9][0-9]* of "\)'$TEST_DIR/',\1./,' \
2598e903e7SBaptiste Daroussin			< $CMP >$tmpfile \
2698e903e7SBaptiste Daroussin			&& mv $tmpfile $CMP
2798e903e7SBaptiste Daroussin		if test ! -f $REF
2898e903e7SBaptiste Daroussin		then
2998e903e7SBaptiste Daroussin			mv $CMP $REF
3098e903e7SBaptiste Daroussin			echo "...saved $REF"
3198e903e7SBaptiste Daroussin		elif ( cmp -s $REF $CMP )
3298e903e7SBaptiste Daroussin		then
3398e903e7SBaptiste Daroussin			echo "...ok $REF"
3498e903e7SBaptiste Daroussin			rm -f $CMP
3598e903e7SBaptiste Daroussin		else
3698e903e7SBaptiste Daroussin			echo "...diff $REF"
3798e903e7SBaptiste Daroussin			diff -u $REF $CMP
38*bb9eb45aSBaptiste Daroussin			errors=1
3998e903e7SBaptiste Daroussin		fi
4098e903e7SBaptiste Daroussin	fi
410c8de5b0SBaptiste Daroussin}
420c8de5b0SBaptiste Daroussin
430c8de5b0SBaptiste Daroussintest_flags() {
440c8de5b0SBaptiste Daroussin	echo "** testing flags $*"
450c8de5b0SBaptiste Daroussin	root=$1
460c8de5b0SBaptiste Daroussin	ROOT=test-$root
470c8de5b0SBaptiste Daroussin	shift 1
480c8de5b0SBaptiste Daroussin	$YACC $* >$ROOT.output \
490c8de5b0SBaptiste Daroussin	    2>&1 >$ROOT.error
500c8de5b0SBaptiste Daroussin	for type in .output .error
510c8de5b0SBaptiste Daroussin	do
520c8de5b0SBaptiste Daroussin		NEW=$ROOT$type
530c8de5b0SBaptiste Daroussin		REF=$REF_DIR/$root$type
540c8de5b0SBaptiste Daroussin		test_diffs
550c8de5b0SBaptiste Daroussin	done
560c8de5b0SBaptiste Daroussin}
570c8de5b0SBaptiste Daroussin
580c8de5b0SBaptiste Daroussinif test $# = 1
590c8de5b0SBaptiste Daroussinthen
600c8de5b0SBaptiste Daroussin	PROG_DIR=`pwd`
610c8de5b0SBaptiste Daroussin	TEST_DIR=$1
620c8de5b0SBaptiste Daroussin	PROG_DIR=`echo "$PROG_DIR" | sed -e 's/ /\\\\ /g'`
630c8de5b0SBaptiste Daroussin	TEST_DIR=`echo "$TEST_DIR" | sed -e 's/ /\\\\ /g'`
640c8de5b0SBaptiste Daroussinelse
650c8de5b0SBaptiste Daroussin	PROG_DIR=..
660c8de5b0SBaptiste Daroussin	TEST_DIR=.
670c8de5b0SBaptiste Daroussinfi
680c8de5b0SBaptiste Daroussin
690c8de5b0SBaptiste DaroussinYACC=$PROG_DIR/yacc
70*bb9eb45aSBaptiste DaroussinYACC_escaped=`echo "$PROG_DIR/yacc" | sed -e 's/\./\\\./g'`
710c8de5b0SBaptiste Daroussin
720c8de5b0SBaptiste Daroussintmpfile=temp$$
730c8de5b0SBaptiste Daroussin
74*bb9eb45aSBaptiste DaroussinifBTYACC=`fgrep -l 'define YYBTYACC' $PROG_DIR/config.h > /dev/null; test $? != 0; echo $?`
750c8de5b0SBaptiste Daroussin
760c8de5b0SBaptiste Daroussinif test $ifBTYACC = 0; then
770c8de5b0SBaptiste Daroussin	REF_DIR=${TEST_DIR}/yacc
780c8de5b0SBaptiste Daroussinelse
790c8de5b0SBaptiste Daroussin	REF_DIR=${TEST_DIR}/btyacc
800c8de5b0SBaptiste Daroussinfi
810c8de5b0SBaptiste Daroussin
820c8de5b0SBaptiste Daroussinrm -f ${REF_DIR}/test-*
830c8de5b0SBaptiste Daroussin
840c8de5b0SBaptiste Daroussinecho '** '`date`
850c8de5b0SBaptiste Daroussin
860c8de5b0SBaptiste Daroussin# Tests which do not need files
870c8de5b0SBaptiste DaroussinMYFILE=nosuchfile
880c8de5b0SBaptiste Daroussintest_flags help -z
890c8de5b0SBaptiste Daroussintest_flags big_b -B
900c8de5b0SBaptiste Daroussintest_flags big_l -L
910c8de5b0SBaptiste Daroussin
920c8de5b0SBaptiste Daroussin# Test attempts to read non-existent file
930c8de5b0SBaptiste Daroussinrm -f $MYFILE.*
940c8de5b0SBaptiste Daroussintest_flags nostdin - $MYFILE.y
950c8de5b0SBaptiste Daroussintest_flags no_opts -- $MYFILE.y
960c8de5b0SBaptiste Daroussin
970c8de5b0SBaptiste Daroussin# Test attempts to write to readonly file
980c8de5b0SBaptiste Daroussintouch $MYFILE.y
990c8de5b0SBaptiste Daroussin
1000c8de5b0SBaptiste Daroussintouch $MYFILE.c
1010c8de5b0SBaptiste Daroussinchmod 444 $MYFILE.*
1020c8de5b0SBaptiste Daroussintest_flags no_b_opt   -b
1030c8de5b0SBaptiste Daroussintest_flags no_b_opt1  -bBASE -o $MYFILE.c $MYFILE.y
1040c8de5b0SBaptiste Daroussin
1050c8de5b0SBaptiste Daroussintouch $MYFILE.c
1060c8de5b0SBaptiste Daroussinchmod 444 $MYFILE.*
1070c8de5b0SBaptiste Daroussintest_flags no_p_opt   -p
1080c8de5b0SBaptiste Daroussintest_flags no_p_opt1  -pBASE -o $MYFILE.c $MYFILE.y
1090c8de5b0SBaptiste Daroussinrm -f BASE$MYFILE.c
1100c8de5b0SBaptiste Daroussin
1110c8de5b0SBaptiste Daroussintouch $MYFILE.dot
1120c8de5b0SBaptiste Daroussinchmod 444 $MYFILE.*
1130c8de5b0SBaptiste Daroussintest_flags no_graph   -g -o $MYFILE.c $MYFILE.y
1140c8de5b0SBaptiste Daroussinrm -f $MYFILE.dot
1150c8de5b0SBaptiste Daroussin
1160c8de5b0SBaptiste Daroussintouch $MYFILE.output
1170c8de5b0SBaptiste Daroussinchmod 444 $MYFILE.*
1180c8de5b0SBaptiste Daroussintest_flags no_verbose -v -o $MYFILE.c $MYFILE.y
1190c8de5b0SBaptiste Daroussintest_flags no_output  -o $MYFILE.output $MYFILE.y
1200c8de5b0SBaptiste Daroussintest_flags no_output1  -o$MYFILE.output $MYFILE.y
1210c8de5b0SBaptiste Daroussintest_flags no_output2  -o
1220c8de5b0SBaptiste Daroussinrm -f $MYFILE.output
1230c8de5b0SBaptiste Daroussin
1240c8de5b0SBaptiste Daroussintouch $MYFILE.h
1250c8de5b0SBaptiste Daroussinchmod 444 $MYFILE.*
1260c8de5b0SBaptiste Daroussintest_flags no_defines -d -o $MYFILE.c $MYFILE.y
1270c8de5b0SBaptiste Daroussinrm -f $MYFILE.h
1280c8de5b0SBaptiste Daroussin
1290c8de5b0SBaptiste Daroussintouch $MYFILE.i
1300c8de5b0SBaptiste Daroussinchmod 444 $MYFILE.*
1310c8de5b0SBaptiste Daroussintest_flags no_include -i -o $MYFILE.c $MYFILE.y
1320c8de5b0SBaptiste Daroussinrm -f $MYFILE.i
1330c8de5b0SBaptiste Daroussin
1340c8de5b0SBaptiste Daroussintouch $MYFILE.code.c
1350c8de5b0SBaptiste Daroussinchmod 444 $MYFILE.*
1360c8de5b0SBaptiste Daroussintest_flags no_code_c -r -o $MYFILE.c $MYFILE.y
1370c8de5b0SBaptiste Daroussinrm -f $MYFILE.code.c
1380c8de5b0SBaptiste Daroussin
1390c8de5b0SBaptiste Daroussinrm -f $MYFILE.*
1400c8de5b0SBaptiste Daroussin
1410c8de5b0SBaptiste Daroussinfor input in ${TEST_DIR}/*.y
1420c8de5b0SBaptiste Daroussindo
1430c8de5b0SBaptiste Daroussin	case $input in
1440c8de5b0SBaptiste Daroussin	test-*)
1450c8de5b0SBaptiste Daroussin		echo "?? ignored $input"
1460c8de5b0SBaptiste Daroussin		;;
1470c8de5b0SBaptiste Daroussin	*)
1480c8de5b0SBaptiste Daroussin		root=`basename $input .y`
1490c8de5b0SBaptiste Daroussin		ROOT="test-$root"
1500c8de5b0SBaptiste Daroussin		prefix=${root}_
1510c8de5b0SBaptiste Daroussin
1520c8de5b0SBaptiste Daroussin		OPTS=
1530c8de5b0SBaptiste Daroussin		OPT2=
1540c8de5b0SBaptiste Daroussin		OOPT=
1550c8de5b0SBaptiste Daroussin		TYPE=".error .output .tab.c .tab.h"
1560c8de5b0SBaptiste Daroussin		case $input in
1570c8de5b0SBaptiste Daroussin		${TEST_DIR}/btyacc_*)
1580c8de5b0SBaptiste Daroussin			if test $ifBTYACC = 0; then continue; fi
1590c8de5b0SBaptiste Daroussin			OPTS="$OPTS -B"
1600c8de5b0SBaptiste Daroussin			prefix=`echo "$prefix" | sed -e 's/^btyacc_//'`
1610c8de5b0SBaptiste Daroussin			;;
1620c8de5b0SBaptiste Daroussin		${TEST_DIR}/grammar*)
1630c8de5b0SBaptiste Daroussin			OPTS="$OPTS -g"
1640c8de5b0SBaptiste Daroussin			TYPE="$TYPE .dot"
1650c8de5b0SBaptiste Daroussin			;;
1660c8de5b0SBaptiste Daroussin		${TEST_DIR}/code_debug*)
1670c8de5b0SBaptiste Daroussin			OPTS="$OPTS -t -i"
1680c8de5b0SBaptiste Daroussin			OOPT=rename_debug.c
1690c8de5b0SBaptiste Daroussin			TYPE="$TYPE .i"
1700c8de5b0SBaptiste Daroussin			prefix=
1710c8de5b0SBaptiste Daroussin			;;
1720c8de5b0SBaptiste Daroussin		${TEST_DIR}/code_*)
1730c8de5b0SBaptiste Daroussin			OPTS="$OPTS -r"
1740c8de5b0SBaptiste Daroussin			TYPE="$TYPE .code.c"
1750c8de5b0SBaptiste Daroussin			prefix=`echo "$prefix" | sed -e 's/^code_//'`
1760c8de5b0SBaptiste Daroussin			;;
1770c8de5b0SBaptiste Daroussin		${TEST_DIR}/pure_*)
1780c8de5b0SBaptiste Daroussin			OPTS="$OPTS -P"
1790c8de5b0SBaptiste Daroussin			prefix=`echo "$prefix" | sed -e 's/^pure_//'`
1800c8de5b0SBaptiste Daroussin			;;
1810c8de5b0SBaptiste Daroussin		${TEST_DIR}/quote_*)
1820c8de5b0SBaptiste Daroussin			OPT2="-s"
1830c8de5b0SBaptiste Daroussin			;;
1840c8de5b0SBaptiste Daroussin		${TEST_DIR}/inherit*|\
1850c8de5b0SBaptiste Daroussin		${TEST_DIR}/err_inherit*)
1860c8de5b0SBaptiste Daroussin			if test $ifBTYACC = 0; then continue; fi
1870c8de5b0SBaptiste Daroussin			;;
1880c8de5b0SBaptiste Daroussin		esac
1890c8de5b0SBaptiste Daroussin
1900c8de5b0SBaptiste Daroussin		echo "** testing $input"
1910c8de5b0SBaptiste Daroussin
1920c8de5b0SBaptiste Daroussin		test -n "$prefix" && prefix="-p $prefix"
1930c8de5b0SBaptiste Daroussin
1940c8de5b0SBaptiste Daroussin		for opt2 in "" $OPT2
1950c8de5b0SBaptiste Daroussin		do
1960c8de5b0SBaptiste Daroussin			output=$OOPT
1970c8de5b0SBaptiste Daroussin			if test -n "$output"
1980c8de5b0SBaptiste Daroussin			then
1990c8de5b0SBaptiste Daroussin				output="-o $output"
2000c8de5b0SBaptiste Daroussin				error=`basename $OOPT .c`.error
2010c8de5b0SBaptiste Daroussin			else
2020c8de5b0SBaptiste Daroussin				error=${ROOT}${opt2}.error
2030c8de5b0SBaptiste Daroussin			fi
2040c8de5b0SBaptiste Daroussin
2050c8de5b0SBaptiste Daroussin			$YACC $OPTS $opt2 -v -d $output $prefix -b $ROOT${opt2} $input 2>$error
2060c8de5b0SBaptiste Daroussin			for type in $TYPE
2070c8de5b0SBaptiste Daroussin			do
2080c8de5b0SBaptiste Daroussin				REF=${REF_DIR}/${root}${opt2}${type}
2090c8de5b0SBaptiste Daroussin
2100c8de5b0SBaptiste Daroussin				# handle renaming due to "-o" option
2110c8de5b0SBaptiste Daroussin				if test -n "$OOPT"
2120c8de5b0SBaptiste Daroussin				then
2130c8de5b0SBaptiste Daroussin					case $type in
2140c8de5b0SBaptiste Daroussin					*.tab.c)
2150c8de5b0SBaptiste Daroussin						type=.c
2160c8de5b0SBaptiste Daroussin						;;
2170c8de5b0SBaptiste Daroussin					*.tab.h)
2180c8de5b0SBaptiste Daroussin						type=.h
2190c8de5b0SBaptiste Daroussin						;;
2200c8de5b0SBaptiste Daroussin					*)
2210c8de5b0SBaptiste Daroussin						;;
2220c8de5b0SBaptiste Daroussin					esac
2230c8de5b0SBaptiste Daroussin					NEW=`basename $OOPT .c`${type}
2240c8de5b0SBaptiste Daroussin					case $NEW in
2250c8de5b0SBaptiste Daroussin					test-*)
2260c8de5b0SBaptiste Daroussin						;;
2270c8de5b0SBaptiste Daroussin					*)
2280c8de5b0SBaptiste Daroussin						if test -f "$NEW"
2290c8de5b0SBaptiste Daroussin						then
2300c8de5b0SBaptiste Daroussin							REF=${REF_DIR}/$NEW
2310c8de5b0SBaptiste Daroussin							mv $NEW test-$NEW
2320c8de5b0SBaptiste Daroussin							NEW=test-$NEW
2330c8de5b0SBaptiste Daroussin						fi
2340c8de5b0SBaptiste Daroussin						;;
2350c8de5b0SBaptiste Daroussin					esac
2360c8de5b0SBaptiste Daroussin				else
2370c8de5b0SBaptiste Daroussin					NEW=${ROOT}${opt2}${type}
2380c8de5b0SBaptiste Daroussin				fi
2390c8de5b0SBaptiste Daroussin				test_diffs
24098e903e7SBaptiste Daroussin			done
24198e903e7SBaptiste Daroussin		done
24298e903e7SBaptiste Daroussin		;;
24398e903e7SBaptiste Daroussin	esac
24498e903e7SBaptiste Daroussindone
245*bb9eb45aSBaptiste Daroussin
246*bb9eb45aSBaptiste Daroussinexit $errors
247