blob: d9faf0bd76a60c54da653f18d49bd7f05e435c4b (
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
#!/bin/sh
# $Id: run_test.sh,v 1.22 2014/04/09 11:00:45 tom Exp $
# vi:ts=4 sw=4:
# NEW is the file created by the testcase
# REF is the reference file against which to compare
test_diffs() {
# echo "...test_diffs $NEW vs $REF"
mv -f $NEW ${REF_DIR}/
CMP=${REF_DIR}/${NEW}
if test ! -f $CMP
then
echo "...not found $CMP"
else
sed -e s,$NEW,$REF, \
-e "s%$YACC%YACC%" \
-e '/YYPATCH/s/[0-9][0-9]*/"yyyymmdd"/' \
-e '/#define YYPATCH/s/PATCH/CHECK/' \
-e 's,#line \([1-9][0-9]*\) "'$REF_DIR'/,#line \1 ",' \
-e 's,#line \([1-9][0-9]*\) "'$TEST_DIR'/,#line \1 ",' \
< $CMP >$tmpfile \
&& mv $tmpfile $CMP
if test ! -f $REF
then
mv $CMP $REF
echo "...saved $REF"
elif ( cmp -s $REF $CMP )
then
echo "...ok $REF"
rm -f $CMP
else
echo "...diff $REF"
diff -u $REF $CMP
fi
fi
}
test_flags() {
echo "** testing flags $*"
root=$1
ROOT=test-$root
shift 1
$YACC $* >$ROOT.output \
2>&1 >$ROOT.error
for type in .output .error
do
NEW=$ROOT$type
REF=$REF_DIR/$root$type
test_diffs
done
}
if test $# = 1
then
PROG_DIR=`pwd`
TEST_DIR=$1
PROG_DIR=`echo "$PROG_DIR" | sed -e 's/ /\\\\ /g'`
TEST_DIR=`echo "$TEST_DIR" | sed -e 's/ /\\\\ /g'`
else
PROG_DIR=..
TEST_DIR=.
fi
YACC=$PROG_DIR/yacc
tmpfile=temp$$
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
rm -f ${REF_DIR}/test-*
echo '** '`date`
# Tests which do not need files
MYFILE=nosuchfile
test_flags help -z
test_flags big_b -B
test_flags big_l -L
# Test attempts to read non-existent file
rm -f $MYFILE.*
test_flags nostdin - $MYFILE.y
test_flags no_opts -- $MYFILE.y
# Test attempts to write to readonly file
touch $MYFILE.y
touch $MYFILE.c
chmod 444 $MYFILE.*
test_flags no_b_opt -b
test_flags no_b_opt1 -bBASE -o $MYFILE.c $MYFILE.y
touch $MYFILE.c
chmod 444 $MYFILE.*
test_flags no_p_opt -p
test_flags no_p_opt1 -pBASE -o $MYFILE.c $MYFILE.y
rm -f BASE$MYFILE.c
touch $MYFILE.dot
chmod 444 $MYFILE.*
test_flags no_graph -g -o $MYFILE.c $MYFILE.y
rm -f $MYFILE.dot
touch $MYFILE.output
chmod 444 $MYFILE.*
test_flags no_verbose -v -o $MYFILE.c $MYFILE.y
test_flags no_output -o $MYFILE.output $MYFILE.y
test_flags no_output1 -o$MYFILE.output $MYFILE.y
test_flags no_output2 -o
rm -f $MYFILE.output
touch $MYFILE.h
chmod 444 $MYFILE.*
test_flags no_defines -d -o $MYFILE.c $MYFILE.y
rm -f $MYFILE.h
touch $MYFILE.i
chmod 444 $MYFILE.*
test_flags no_include -i -o $MYFILE.c $MYFILE.y
rm -f $MYFILE.i
touch $MYFILE.code.c
chmod 444 $MYFILE.*
test_flags no_code_c -r -o $MYFILE.c $MYFILE.y
rm -f $MYFILE.code.c
rm -f $MYFILE.*
for input in ${TEST_DIR}/*.y
do
case $input in
test-*)
echo "?? ignored $input"
;;
*)
root=`basename $input .y`
ROOT="test-$root"
prefix=${root}_
OPTS=
OPT2=
OOPT=
TYPE=".error .output .tab.c .tab.h"
case $input in
${TEST_DIR}/btyacc_*)
if test $ifBTYACC = 0; then continue; fi
OPTS="$OPTS -B"
prefix=`echo "$prefix" | sed -e 's/^btyacc_//'`
;;
${TEST_DIR}/grammar*)
OPTS="$OPTS -g"
TYPE="$TYPE .dot"
;;
${TEST_DIR}/code_debug*)
OPTS="$OPTS -t -i"
OOPT=rename_debug.c
TYPE="$TYPE .i"
prefix=
;;
${TEST_DIR}/code_*)
OPTS="$OPTS -r"
TYPE="$TYPE .code.c"
prefix=`echo "$prefix" | sed -e 's/^code_//'`
;;
${TEST_DIR}/pure_*)
OPTS="$OPTS -P"
prefix=`echo "$prefix" | sed -e 's/^pure_//'`
;;
${TEST_DIR}/quote_*)
OPT2="-s"
;;
${TEST_DIR}/inherit*|\
${TEST_DIR}/err_inherit*)
if test $ifBTYACC = 0; then continue; fi
;;
esac
echo "** testing $input"
test -n "$prefix" && prefix="-p $prefix"
for opt2 in "" $OPT2
do
output=$OOPT
if test -n "$output"
then
output="-o $output"
error=`basename $OOPT .c`.error
else
error=${ROOT}${opt2}.error
fi
$YACC $OPTS $opt2 -v -d $output $prefix -b $ROOT${opt2} $input 2>$error
for type in $TYPE
do
REF=${REF_DIR}/${root}${opt2}${type}
# handle renaming due to "-o" option
if test -n "$OOPT"
then
case $type in
*.tab.c)
type=.c
;;
*.tab.h)
type=.h
;;
*)
;;
esac
NEW=`basename $OOPT .c`${type}
case $NEW in
test-*)
;;
*)
if test -f "$NEW"
then
REF=${REF_DIR}/$NEW
mv $NEW test-$NEW
NEW=test-$NEW
fi
;;
esac
else
NEW=${ROOT}${opt2}${type}
fi
test_diffs
done
done
;;
esac
done
|