xref: /freebsd/contrib/byacc/test/run_test.sh (revision 8e022d3cdea10ee1039a632f670c27fd93f65625)
198e903e7SBaptiste Daroussin#!/bin/sh
2*8e022d3cSDag-Erling Smørgrav# $Id: run_test.sh,v 1.37 2022/11/06 21:55:25 tom Exp $
398e903e7SBaptiste Daroussin# vi:ts=4 sw=4:
498e903e7SBaptiste Daroussin
5bb9eb45aSBaptiste Daroussinerrors=0
6bb9eb45aSBaptiste 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"
11*8e022d3cSDag-Erling Smørgrav	mv -f "$NEW" "${REF_DIR}/"
120c8de5b0SBaptiste Daroussin	CMP=${REF_DIR}/${NEW}
13*8e022d3cSDag-Erling Smørgrav	if test ! -f "$CMP"
1498e903e7SBaptiste Daroussin	then
1598e903e7SBaptiste Daroussin		echo "...not found $CMP"
16bb9eb45aSBaptiste Daroussin		errors=1
1798e903e7SBaptiste Daroussin	else
18*8e022d3cSDag-Erling Smørgrav		sed	-e "s,$NEW,$REF," \
19bb9eb45aSBaptiste Daroussin			-e "s%$YACC_escaped%YACC%" \
20b53bb29fSJung-uk Kim			-e "s%^yacc\>%YACC%" \
21b53bb29fSJung-uk Kim			-e "s%YACC:.*option.*$%YACC: error message%" \
22*8e022d3cSDag-Erling Smørgrav			-e "s%yacc:.*option.*$%YACC: error message%" \
23b53bb29fSJung-uk Kim			-e "s%^Usage: yacc\>%Usage: YACC%" \
240c8de5b0SBaptiste Daroussin			-e '/YYPATCH/s/[0-9][0-9]*/"yyyymmdd"/' \
250c8de5b0SBaptiste Daroussin			-e '/#define YYPATCH/s/PATCH/CHECK/' \
26*8e022d3cSDag-Erling Smørgrav			-e 's,#line \([1-9][0-9]*\) "'"$REF_DIR"'/,#line \1 ",' \
27*8e022d3cSDag-Erling Smørgrav			-e 's,#line \([1-9][0-9]*\) "'"$TEST_DIR"'/,#line \1 ",' \
28*8e022d3cSDag-Erling Smørgrav			-e 's/^typedef \(short\|long\) YYINT;$/typedef int YYINT;/' \
29*8e022d3cSDag-Erling Smørgrav			-e 's,\(YACC:.* line [0-9][0-9]* of "\)'"$TEST_DIR/"',\1./,' \
30*8e022d3cSDag-Erling Smørgrav			< "$CMP" >"$tmpfile" \
31*8e022d3cSDag-Erling Smørgrav			&& mv "$tmpfile" "$CMP"
32*8e022d3cSDag-Erling Smørgrav		if test ! -f "$REF"
3398e903e7SBaptiste Daroussin		then
34*8e022d3cSDag-Erling Smørgrav			mv "$CMP" "$REF"
3598e903e7SBaptiste Daroussin			echo "...saved $REF"
36*8e022d3cSDag-Erling Smørgrav		elif ( cmp -s "$REF" "$CMP" )
3798e903e7SBaptiste Daroussin		then
3898e903e7SBaptiste Daroussin			echo "...ok $REF"
39*8e022d3cSDag-Erling Smørgrav			rm -f "$CMP"
4098e903e7SBaptiste Daroussin		else
4198e903e7SBaptiste Daroussin			echo "...diff $REF"
42*8e022d3cSDag-Erling Smørgrav			diff -c "$REF" "$CMP"
43bb9eb45aSBaptiste Daroussin			errors=1
4498e903e7SBaptiste Daroussin		fi
4598e903e7SBaptiste Daroussin	fi
460c8de5b0SBaptiste Daroussin}
470c8de5b0SBaptiste Daroussin
480c8de5b0SBaptiste Daroussintest_flags() {
490c8de5b0SBaptiste Daroussin	echo "** testing flags $*"
500c8de5b0SBaptiste Daroussin	root=$1
510c8de5b0SBaptiste Daroussin	ROOT=test-$root
520c8de5b0SBaptiste Daroussin	shift 1
53*8e022d3cSDag-Erling Smørgrav	$YACC "$@" >"$ROOT.output" 2>"$ROOT.error"
540c8de5b0SBaptiste Daroussin	for type in .output .error
550c8de5b0SBaptiste Daroussin	do
560c8de5b0SBaptiste Daroussin		NEW=$ROOT$type
570c8de5b0SBaptiste Daroussin		REF=$REF_DIR/$root$type
580c8de5b0SBaptiste Daroussin		test_diffs
590c8de5b0SBaptiste Daroussin	done
600c8de5b0SBaptiste Daroussin}
610c8de5b0SBaptiste Daroussin
62b53bb29fSJung-uk Kimtest_stdin() {
63b53bb29fSJung-uk Kim	echo "** testing stdin $*"
64b53bb29fSJung-uk Kim	root=$1
65b53bb29fSJung-uk Kim	ROOT=test-$root
66b53bb29fSJung-uk Kim	shift 1
67b53bb29fSJung-uk Kim	opts="$1"
68b53bb29fSJung-uk Kim	shift 1
69b53bb29fSJung-uk Kim	code=`echo "$1"|sed -e 's/y$/c/' -e "s,${TEST_DIR}/,,"`
70b53bb29fSJung-uk Kim	if test "x$opts" = "x-"
71b53bb29fSJung-uk Kim	then
72*8e022d3cSDag-Erling Smørgrav		$YACC -o "$ROOT.$code" $opts <$1 >"$ROOT.output" 2>"$ROOT.error"
73b53bb29fSJung-uk Kim	else
74*8e022d3cSDag-Erling Smørgrav		$YACC -o "$ROOT.$code" $opts  $1 >"$ROOT.output" 2>"$ROOT.error"
75b53bb29fSJung-uk Kim	fi
76b53bb29fSJung-uk Kim	for type in .output .error .$code
77b53bb29fSJung-uk Kim	do
78b53bb29fSJung-uk Kim		NEW=$ROOT$type
79b53bb29fSJung-uk Kim		REF=$REF_DIR/$root$type
80b53bb29fSJung-uk Kim		test_diffs
81b53bb29fSJung-uk Kim	done
82b53bb29fSJung-uk Kim}
83b53bb29fSJung-uk Kim
84b53bb29fSJung-uk Kimtest_defines() {
85b53bb29fSJung-uk Kim	echo "** testing defines $*"
86b53bb29fSJung-uk Kim	root=$1
87b53bb29fSJung-uk Kim	ROOT=test-$root
88b53bb29fSJung-uk Kim	shift 1
89b53bb29fSJung-uk Kim	opts=
90b53bb29fSJung-uk Kim	while test $# != 1
91b53bb29fSJung-uk Kim	do
92b53bb29fSJung-uk Kim		opts="$opts $1"
93b53bb29fSJung-uk Kim		shift 1
94b53bb29fSJung-uk Kim	done
95b53bb29fSJung-uk Kim	head=`echo "$1"|sed -e 's/y$/h/' -e "s,${TEST_DIR}/,,"`
96b53bb29fSJung-uk Kim	code=`echo "$1"|sed -e 's/y$/c/' -e "s,${TEST_DIR}/,,"`
97*8e022d3cSDag-Erling Smørgrav	$YACC $opts -H "$ROOT.$head" $1 >"$ROOT.output" 2>"$ROOT.error"
98b53bb29fSJung-uk Kim	for name in prefix.tab.c y.tab.c
99b53bb29fSJung-uk Kim	do
100b53bb29fSJung-uk Kim		if test -f $name
101b53bb29fSJung-uk Kim		then
102*8e022d3cSDag-Erling Smørgrav			mv "$name" "$ROOT.$code"
103b53bb29fSJung-uk Kim			break
104b53bb29fSJung-uk Kim		fi
105b53bb29fSJung-uk Kim	done
106b53bb29fSJung-uk Kim	for name in .output .error .$head .$code
107b53bb29fSJung-uk Kim	do
108b53bb29fSJung-uk Kim		NEW=$ROOT$name
109b53bb29fSJung-uk Kim		REF=$REF_DIR/$root$name
110b53bb29fSJung-uk Kim		test_diffs
111b53bb29fSJung-uk Kim	done
112b53bb29fSJung-uk Kim}
113b53bb29fSJung-uk Kim
1140c8de5b0SBaptiste Daroussinif test $# = 1
1150c8de5b0SBaptiste Daroussinthen
1160c8de5b0SBaptiste Daroussin	PROG_DIR=`pwd`
1170c8de5b0SBaptiste Daroussin	TEST_DIR=$1
1180c8de5b0SBaptiste Daroussin	PROG_DIR=`echo "$PROG_DIR" | sed -e 's/ /\\\\ /g'`
1190c8de5b0SBaptiste Daroussin	TEST_DIR=`echo "$TEST_DIR" | sed -e 's/ /\\\\ /g'`
1200c8de5b0SBaptiste Daroussinelse
1210c8de5b0SBaptiste Daroussin	PROG_DIR=..
1220c8de5b0SBaptiste Daroussin	TEST_DIR=.
1230c8de5b0SBaptiste Daroussinfi
1240c8de5b0SBaptiste Daroussin
1250c8de5b0SBaptiste DaroussinYACC=$PROG_DIR/yacc
126bb9eb45aSBaptiste DaroussinYACC_escaped=`echo "$PROG_DIR/yacc" | sed -e 's/\./\\\./g'`
1270c8de5b0SBaptiste Daroussin
1280c8de5b0SBaptiste Daroussintmpfile=temp$$
1290c8de5b0SBaptiste Daroussin
130*8e022d3cSDag-Erling Smørgrav: "${FGREP:=grep -F}"
131*8e022d3cSDag-Erling SmørgravifBTYACC=`$FGREP -l 'define YYBTYACC' $PROG_DIR/config.h > /dev/null; test $? != 0; echo $?`
1320c8de5b0SBaptiste Daroussin
133*8e022d3cSDag-Erling Smørgravif test "$ifBTYACC" = 0; then
1340c8de5b0SBaptiste Daroussin	REF_DIR=${TEST_DIR}/yacc
1350c8de5b0SBaptiste Daroussinelse
1360c8de5b0SBaptiste Daroussin	REF_DIR=${TEST_DIR}/btyacc
1370c8de5b0SBaptiste Daroussinfi
1380c8de5b0SBaptiste Daroussin
1390c8de5b0SBaptiste Daroussinrm -f ${REF_DIR}/test-*
1400c8de5b0SBaptiste Daroussin
141*8e022d3cSDag-Erling Smørgravecho "** `date`"
1420c8de5b0SBaptiste Daroussin
1430c8de5b0SBaptiste Daroussin# Tests which do not need files
1440c8de5b0SBaptiste DaroussinMYFILE=nosuchfile
1450c8de5b0SBaptiste Daroussintest_flags help -z
1460c8de5b0SBaptiste Daroussintest_flags big_b -B
1470c8de5b0SBaptiste Daroussintest_flags big_l -L
1480c8de5b0SBaptiste Daroussin
1490c8de5b0SBaptiste Daroussin# Test attempts to read non-existent file
1500c8de5b0SBaptiste Daroussinrm -f $MYFILE.*
1510c8de5b0SBaptiste Daroussintest_flags nostdin - $MYFILE.y
1520c8de5b0SBaptiste Daroussintest_flags no_opts -- $MYFILE.y
1530c8de5b0SBaptiste Daroussin
1540c8de5b0SBaptiste Daroussin# Test attempts to write to readonly file
1550c8de5b0SBaptiste Daroussintouch $MYFILE.y
1560c8de5b0SBaptiste Daroussin
1570c8de5b0SBaptiste Daroussintouch $MYFILE.c
1580c8de5b0SBaptiste Daroussinchmod 444 $MYFILE.*
1590c8de5b0SBaptiste Daroussintest_flags no_b_opt   -b
1600c8de5b0SBaptiste Daroussintest_flags no_b_opt1  -bBASE -o $MYFILE.c $MYFILE.y
1610c8de5b0SBaptiste Daroussin
1620c8de5b0SBaptiste Daroussintouch $MYFILE.c
1630c8de5b0SBaptiste Daroussinchmod 444 $MYFILE.*
1640c8de5b0SBaptiste Daroussintest_flags no_p_opt   -p
1650c8de5b0SBaptiste Daroussintest_flags no_p_opt1  -pBASE -o $MYFILE.c $MYFILE.y
1660c8de5b0SBaptiste Daroussinrm -f BASE$MYFILE.c
1670c8de5b0SBaptiste Daroussin
1680c8de5b0SBaptiste Daroussintouch $MYFILE.dot
1690c8de5b0SBaptiste Daroussinchmod 444 $MYFILE.*
1700c8de5b0SBaptiste Daroussintest_flags no_graph   -g -o $MYFILE.c $MYFILE.y
1710c8de5b0SBaptiste Daroussinrm -f $MYFILE.dot
1720c8de5b0SBaptiste Daroussin
1730c8de5b0SBaptiste Daroussintouch $MYFILE.output
1740c8de5b0SBaptiste Daroussinchmod 444 $MYFILE.*
1750c8de5b0SBaptiste Daroussintest_flags no_verbose -v -o $MYFILE.c $MYFILE.y
1760c8de5b0SBaptiste Daroussintest_flags no_output  -o $MYFILE.output $MYFILE.y
1770c8de5b0SBaptiste Daroussintest_flags no_output1  -o$MYFILE.output $MYFILE.y
1780c8de5b0SBaptiste Daroussintest_flags no_output2  -o
1790c8de5b0SBaptiste Daroussinrm -f $MYFILE.output
1800c8de5b0SBaptiste Daroussin
1810c8de5b0SBaptiste Daroussintouch $MYFILE.h
1820c8de5b0SBaptiste Daroussinchmod 444 $MYFILE.*
1830c8de5b0SBaptiste Daroussintest_flags no_defines -d -o $MYFILE.c $MYFILE.y
1840c8de5b0SBaptiste Daroussinrm -f $MYFILE.h
1850c8de5b0SBaptiste Daroussin
1860c8de5b0SBaptiste Daroussintouch $MYFILE.i
1870c8de5b0SBaptiste Daroussinchmod 444 $MYFILE.*
1880c8de5b0SBaptiste Daroussintest_flags no_include -i -o $MYFILE.c $MYFILE.y
1890c8de5b0SBaptiste Daroussinrm -f $MYFILE.i
1900c8de5b0SBaptiste Daroussin
1910c8de5b0SBaptiste Daroussintouch $MYFILE.code.c
1920c8de5b0SBaptiste Daroussinchmod 444 $MYFILE.*
1930c8de5b0SBaptiste Daroussintest_flags no_code_c -r -o $MYFILE.c $MYFILE.y
1940c8de5b0SBaptiste Daroussinrm -f $MYFILE.code.c
1950c8de5b0SBaptiste Daroussin
1960c8de5b0SBaptiste Daroussinrm -f $MYFILE.*
1970c8de5b0SBaptiste Daroussin
198b53bb29fSJung-uk Kim# Test special cases
199b53bb29fSJung-uk Kimtest_stdin stdin1 - ${TEST_DIR}/calc.y
200b53bb29fSJung-uk Kimtest_stdin stdin2 -- ${TEST_DIR}/calc.y
201b53bb29fSJung-uk Kim
202b53bb29fSJung-uk Kimtest_defines defines1 ${TEST_DIR}/calc.y
203b53bb29fSJung-uk Kimtest_defines defines2 -d ${TEST_DIR}/calc.y
204b53bb29fSJung-uk Kimtest_defines defines3 -b prefix ${TEST_DIR}/calc.y
205b53bb29fSJung-uk Kim
206*8e022d3cSDag-Erling Smørgravfor input in "${TEST_DIR}"/*.y
2070c8de5b0SBaptiste Daroussindo
2080c8de5b0SBaptiste Daroussin	case $input in
2090c8de5b0SBaptiste Daroussin	test-*)
2100c8de5b0SBaptiste Daroussin		echo "?? ignored $input"
2110c8de5b0SBaptiste Daroussin		;;
2120c8de5b0SBaptiste Daroussin	*)
213*8e022d3cSDag-Erling Smørgrav		root=`basename "$input" .y`
2140c8de5b0SBaptiste Daroussin		ROOT="test-$root"
215*8e022d3cSDag-Erling Smørgrav		prefix=`echo "${root}_" | sed -e 's/[.]/_/g'`
2160c8de5b0SBaptiste Daroussin
2170c8de5b0SBaptiste Daroussin		OPTS=
2180c8de5b0SBaptiste Daroussin		OPT2=
2190c8de5b0SBaptiste Daroussin		OOPT=
2200c8de5b0SBaptiste Daroussin		TYPE=".error .output .tab.c .tab.h"
2210c8de5b0SBaptiste Daroussin		case $input in
2220c8de5b0SBaptiste Daroussin		${TEST_DIR}/btyacc_*)
223*8e022d3cSDag-Erling Smørgrav			if test "$ifBTYACC" = 0; then continue; fi
2240c8de5b0SBaptiste Daroussin			OPTS="$OPTS -B"
2250c8de5b0SBaptiste Daroussin			prefix=`echo "$prefix" | sed -e 's/^btyacc_//'`
2260c8de5b0SBaptiste Daroussin			;;
2270c8de5b0SBaptiste Daroussin		${TEST_DIR}/grammar*)
2280c8de5b0SBaptiste Daroussin			OPTS="$OPTS -g"
2290c8de5b0SBaptiste Daroussin			TYPE="$TYPE .dot"
2300c8de5b0SBaptiste Daroussin			;;
2310c8de5b0SBaptiste Daroussin		${TEST_DIR}/code_debug*)
2320c8de5b0SBaptiste Daroussin			OPTS="$OPTS -t -i"
2330c8de5b0SBaptiste Daroussin			OOPT=rename_debug.c
2340c8de5b0SBaptiste Daroussin			TYPE="$TYPE .i"
2350c8de5b0SBaptiste Daroussin			prefix=
2360c8de5b0SBaptiste Daroussin			;;
2370c8de5b0SBaptiste Daroussin		${TEST_DIR}/code_*)
2380c8de5b0SBaptiste Daroussin			OPTS="$OPTS -r"
2390c8de5b0SBaptiste Daroussin			TYPE="$TYPE .code.c"
2400c8de5b0SBaptiste Daroussin			prefix=`echo "$prefix" | sed -e 's/^code_//'`
2410c8de5b0SBaptiste Daroussin			;;
2420c8de5b0SBaptiste Daroussin		${TEST_DIR}/pure_*)
2430c8de5b0SBaptiste Daroussin			OPTS="$OPTS -P"
2440c8de5b0SBaptiste Daroussin			prefix=`echo "$prefix" | sed -e 's/^pure_//'`
2450c8de5b0SBaptiste Daroussin			;;
2460c8de5b0SBaptiste Daroussin		${TEST_DIR}/quote_*)
2470c8de5b0SBaptiste Daroussin			OPT2="-s"
2480c8de5b0SBaptiste Daroussin			;;
2490c8de5b0SBaptiste Daroussin		${TEST_DIR}/inherit*|\
2500c8de5b0SBaptiste Daroussin		${TEST_DIR}/err_inherit*)
251*8e022d3cSDag-Erling Smørgrav			if test "$ifBTYACC" = 0; then continue; fi
2520c8de5b0SBaptiste Daroussin			;;
2530c8de5b0SBaptiste Daroussin		esac
2540c8de5b0SBaptiste Daroussin
2550c8de5b0SBaptiste Daroussin		echo "** testing $input"
2560c8de5b0SBaptiste Daroussin
2570c8de5b0SBaptiste Daroussin		test -n "$prefix" && prefix="-p $prefix"
2580c8de5b0SBaptiste Daroussin
2590c8de5b0SBaptiste Daroussin		for opt2 in "" $OPT2
2600c8de5b0SBaptiste Daroussin		do
2610c8de5b0SBaptiste Daroussin			output=$OOPT
2620c8de5b0SBaptiste Daroussin			if test -n "$output"
2630c8de5b0SBaptiste Daroussin			then
2640c8de5b0SBaptiste Daroussin				output="-o $output"
265*8e022d3cSDag-Erling Smørgrav				error=`basename "$OOPT" .c`.error
2660c8de5b0SBaptiste Daroussin			else
2670c8de5b0SBaptiste Daroussin				error=${ROOT}${opt2}.error
2680c8de5b0SBaptiste Daroussin			fi
2690c8de5b0SBaptiste Daroussin
270*8e022d3cSDag-Erling Smørgrav			$YACC $OPTS $opt2 -v -d $output $prefix -b "$ROOT${opt2}" "$input" 2>"$error"
2710c8de5b0SBaptiste Daroussin			for type in $TYPE
2720c8de5b0SBaptiste Daroussin			do
2730c8de5b0SBaptiste Daroussin				REF=${REF_DIR}/${root}${opt2}${type}
2740c8de5b0SBaptiste Daroussin
2750c8de5b0SBaptiste Daroussin				# handle renaming due to "-o" option
2760c8de5b0SBaptiste Daroussin				if test -n "$OOPT"
2770c8de5b0SBaptiste Daroussin				then
2780c8de5b0SBaptiste Daroussin					case $type in
2790c8de5b0SBaptiste Daroussin					*.tab.c)
2800c8de5b0SBaptiste Daroussin						type=.c
2810c8de5b0SBaptiste Daroussin						;;
2820c8de5b0SBaptiste Daroussin					*.tab.h)
2830c8de5b0SBaptiste Daroussin						type=.h
2840c8de5b0SBaptiste Daroussin						;;
2850c8de5b0SBaptiste Daroussin					*)
2860c8de5b0SBaptiste Daroussin						;;
2870c8de5b0SBaptiste Daroussin					esac
288*8e022d3cSDag-Erling Smørgrav					NEW=`basename "$OOPT" .c`${type}
2890c8de5b0SBaptiste Daroussin					case $NEW in
2900c8de5b0SBaptiste Daroussin					test-*)
2910c8de5b0SBaptiste Daroussin						;;
2920c8de5b0SBaptiste Daroussin					*)
2930c8de5b0SBaptiste Daroussin						if test -f "$NEW"
2940c8de5b0SBaptiste Daroussin						then
2950c8de5b0SBaptiste Daroussin							REF=${REF_DIR}/$NEW
296*8e022d3cSDag-Erling Smørgrav							mv "$NEW" "test-$NEW"
297*8e022d3cSDag-Erling Smørgrav							NEW="test-$NEW"
2980c8de5b0SBaptiste Daroussin						fi
2990c8de5b0SBaptiste Daroussin						;;
3000c8de5b0SBaptiste Daroussin					esac
3010c8de5b0SBaptiste Daroussin				else
302*8e022d3cSDag-Erling Smørgrav					NEW="${ROOT}${opt2}${type}"
3030c8de5b0SBaptiste Daroussin				fi
3040c8de5b0SBaptiste Daroussin				test_diffs
30598e903e7SBaptiste Daroussin			done
30698e903e7SBaptiste Daroussin		done
30798e903e7SBaptiste Daroussin		;;
30898e903e7SBaptiste Daroussin	esac
30998e903e7SBaptiste Daroussindone
310bb9eb45aSBaptiste Daroussin
311bb9eb45aSBaptiste Daroussinexit $errors
312