summaryrefslogtreecommitdiff
path: root/test/run_make.sh
blob: 218a7c52cdc4cc2edad8c9275a56785e9aac94e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/bin/sh
# $Id: run_make.sh,v 1.14 2014/04/06 17:50:57 tom Exp $
# vi:ts=4 sw=4:

# do a test-compile on each of the ".c" files in the test-directory

BISON=`bison --version 2>/dev/null | head -n 1 | sed -e 's/^[^0-9.]*//' -e 's/[^0-9.]*$//'`

if test $# = 1
then
	PROG_DIR=`pwd`
	TEST_DIR=$1
else
	PROG_DIR=..
	TEST_DIR=.
fi
THIS_DIR=`pwd`

ifBTYACC=`fgrep -l 'define YYBTYACC' config.h > /dev/null; test $? != 0; echo $?`

if test $ifBTYACC = 0; then
	REF_DIR=${TEST_DIR}/yacc
else
	REF_DIR=${TEST_DIR}/btyacc
fi

MY_MAKE="make -f $PROG_DIR/makefile srcdir=$PROG_DIR"

run_make() {
	C_FILE=`basename "$1"`
	O_FILE=`basename "$C_FILE" .c`.o
	shift
	cd $REF_DIR
	make -f $PROG_DIR/makefile srcdir=$PROG_DIR $O_FILE $*
	test -f $O_FILE && rm $O_FILE
	cd $THIS_DIR
}

echo '** '`date`
echo "** program is in $PROG_DIR"
echo "** test-files in $REF_DIR"

for input in ${REF_DIR}/*.c
do
	case $input in #(vi
	${REF_DIR}/err_*)
		continue
		;;
	esac

	test -f "$input" || continue

	run_make "$input"

	DEFS=
	case $input in #(vi
	${REF_DIR}/pure_*)
		# DEFS="-DYYLEX_PARAM=flag -DYYLEX_PARAM_TYPE=int"
		;;
	esac

	if test "x$DEFS" != "x"
	then
		run_make "$input" DEFINES="$DEFS"
	fi
done

if test -n "$BISON"
then
	echo "** compare with bison $BISON"
	for input in ${TEST_DIR}/*.y
	do
		test -f "$input" || continue
		case $input in
		${TEST_DIR}/err_*)
			continue
			;;
		${TEST_DIR}/btyacc_*)
			# Bison does not support the btyacc []-action extension.
			continue
			;;
		esac

		# Bison does not support pure-parser from command-line.
		# Also, its support for %expect is generally broken.
		# Work around these issues using a temporary file.

		echo "... testing $input"
		rm -f run_make.[coy]

		case $input in
		${TEST_DIR}/pure_*)
			if test -z `fgrep -l '%pure-parser' $input`
			then
				echo "%pure-parser" >>run_make.y
			fi
			;;
		esac

		sed -e '/^%expect/s,%expect.*,,' $input >>run_make.y

		bison -y run_make.y
		if test -f "y.tab.c"
		then
			sed -e '/^#line/s,"run_make.y","'$input'",' y.tab.c >run_make.c

			rm -f y.tab.c

			input=run_make.c
			object=run_make.o
			if test -f $input
			then
				$MY_MAKE $object DEFINES='-DYYENABLE_NLS=0 -DYYLTYPE_IS_TRIVIAL=1 -DYYSTACK_USE_ALLOCA=0 -DYYMAXDEPTH=0'
			else
				echo "?? $input not found"
			fi
		fi
		rm -f run_make.[coy]
	done
fi

YACC=
for name in /usr/ccs/bin/yacc
do
	if test -f $name
	then
		YACC=$name
	fi
done

if test -n "$YACC"
then
	echo "** compare with $YACC"
	for input in ${TEST_DIR}/*.y
	do
		test -f "$input" || continue

		echo "... testing $input"
		rm -f run_make.[coy]

		case $input in
		pure_*)
			echo "... skipping $input"
			continue;
			;;
		*)
			if fgrep '%pure-parser' $input >/dev/null ||
			   fgrep '%parse-param' $input >/dev/null ||
			   fgrep '%lex-param' $input >/dev/null ||
			   fgrep 'YYLEX_PARAM' $input >/dev/null
			then
				echo "... skipping $input"
				continue;
			fi
			;;
		esac

		sed -e '/^%expect/s,%expect.*,,' $input >>run_make.y

		$YACC run_make.y
		if test -f y.tab.c
		then
			sed -e '/^#line/s,"run_make.y","'$input'",' y.tab.c >run_make.c

			rm -f y.tab.c

			input=run_make.c
			object=run_make.o
			if test -f $input
			then
				$MY_MAKE $object
			else
				echo "?? $input not found"
			fi
		fi
		rm -f run_make.[coy]
	done
fi