]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/byacc/test/run_test.sh
MFC: r257315, r260445, r264803
[FreeBSD/stable/10.git] / contrib / byacc / test / run_test.sh
1 #!/bin/sh
2 # $Id: run_test.sh,v 1.22 2014/04/09 11:00:45 tom Exp $
3 # vi:ts=4 sw=4:
4
5 # NEW is the file created by the testcase
6 # REF is the reference file against which to compare
7 test_diffs() {
8         # echo "...test_diffs $NEW vs $REF"
9         mv -f $NEW ${REF_DIR}/
10         CMP=${REF_DIR}/${NEW}
11         if test ! -f $CMP
12         then
13                 echo "...not found $CMP"
14         else
15                 sed     -e s,$NEW,$REF, \
16                         -e "s%$YACC%YACC%" \
17                         -e '/YYPATCH/s/[0-9][0-9]*/"yyyymmdd"/' \
18                         -e '/#define YYPATCH/s/PATCH/CHECK/' \
19                         -e 's,#line \([1-9][0-9]*\) "'$REF_DIR'/,#line \1 ",' \
20                         -e 's,#line \([1-9][0-9]*\) "'$TEST_DIR'/,#line \1 ",' \
21                         < $CMP >$tmpfile \
22                         && mv $tmpfile $CMP
23                 if test ! -f $REF
24                 then
25                         mv $CMP $REF
26                         echo "...saved $REF"
27                 elif ( cmp -s $REF $CMP )
28                 then
29                         echo "...ok $REF"
30                         rm -f $CMP
31                 else
32                         echo "...diff $REF"
33                         diff -u $REF $CMP
34                 fi
35         fi
36 }
37
38 test_flags() {
39         echo "** testing flags $*"
40         root=$1
41         ROOT=test-$root
42         shift 1
43         $YACC $* >$ROOT.output \
44             2>&1 >$ROOT.error
45         for type in .output .error
46         do
47                 NEW=$ROOT$type
48                 REF=$REF_DIR/$root$type
49                 test_diffs
50         done
51 }
52
53 if test $# = 1
54 then
55         PROG_DIR=`pwd`
56         TEST_DIR=$1
57         PROG_DIR=`echo "$PROG_DIR" | sed -e 's/ /\\\\ /g'`
58         TEST_DIR=`echo "$TEST_DIR" | sed -e 's/ /\\\\ /g'`
59 else
60         PROG_DIR=..
61         TEST_DIR=.
62 fi
63
64 YACC=$PROG_DIR/yacc
65
66 tmpfile=temp$$
67
68 ifBTYACC=`fgrep -l 'define YYBTYACC' config.h > /dev/null; test $? != 0; echo $?`
69
70 if test $ifBTYACC = 0; then
71         REF_DIR=${TEST_DIR}/yacc
72 else
73         REF_DIR=${TEST_DIR}/btyacc
74 fi
75
76 rm -f ${REF_DIR}/test-*
77
78 echo '** '`date`
79
80 # Tests which do not need files
81 MYFILE=nosuchfile
82 test_flags help -z
83 test_flags big_b -B
84 test_flags big_l -L
85
86 # Test attempts to read non-existent file
87 rm -f $MYFILE.*
88 test_flags nostdin - $MYFILE.y
89 test_flags no_opts -- $MYFILE.y
90
91 # Test attempts to write to readonly file
92 touch $MYFILE.y
93
94 touch $MYFILE.c
95 chmod 444 $MYFILE.*
96 test_flags no_b_opt   -b
97 test_flags no_b_opt1  -bBASE -o $MYFILE.c $MYFILE.y
98
99 touch $MYFILE.c
100 chmod 444 $MYFILE.*
101 test_flags no_p_opt   -p
102 test_flags no_p_opt1  -pBASE -o $MYFILE.c $MYFILE.y
103 rm -f BASE$MYFILE.c
104
105 touch $MYFILE.dot
106 chmod 444 $MYFILE.*
107 test_flags no_graph   -g -o $MYFILE.c $MYFILE.y
108 rm -f $MYFILE.dot
109
110 touch $MYFILE.output
111 chmod 444 $MYFILE.*
112 test_flags no_verbose -v -o $MYFILE.c $MYFILE.y
113 test_flags no_output  -o $MYFILE.output $MYFILE.y
114 test_flags no_output1  -o$MYFILE.output $MYFILE.y
115 test_flags no_output2  -o
116 rm -f $MYFILE.output
117
118 touch $MYFILE.h
119 chmod 444 $MYFILE.*
120 test_flags no_defines -d -o $MYFILE.c $MYFILE.y
121 rm -f $MYFILE.h
122
123 touch $MYFILE.i
124 chmod 444 $MYFILE.*
125 test_flags no_include -i -o $MYFILE.c $MYFILE.y
126 rm -f $MYFILE.i
127
128 touch $MYFILE.code.c
129 chmod 444 $MYFILE.*
130 test_flags no_code_c -r -o $MYFILE.c $MYFILE.y
131 rm -f $MYFILE.code.c
132
133 rm -f $MYFILE.*
134
135 for input in ${TEST_DIR}/*.y
136 do
137         case $input in
138         test-*)
139                 echo "?? ignored $input"
140                 ;;
141         *)
142                 root=`basename $input .y`
143                 ROOT="test-$root"
144                 prefix=${root}_
145
146                 OPTS=
147                 OPT2=
148                 OOPT=
149                 TYPE=".error .output .tab.c .tab.h"
150                 case $input in
151                 ${TEST_DIR}/btyacc_*)
152                         if test $ifBTYACC = 0; then continue; fi
153                         OPTS="$OPTS -B"
154                         prefix=`echo "$prefix" | sed -e 's/^btyacc_//'`
155                         ;;
156                 ${TEST_DIR}/grammar*)
157                         OPTS="$OPTS -g"
158                         TYPE="$TYPE .dot"
159                         ;;
160                 ${TEST_DIR}/code_debug*)
161                         OPTS="$OPTS -t -i"
162                         OOPT=rename_debug.c
163                         TYPE="$TYPE .i"
164                         prefix=
165                         ;;
166                 ${TEST_DIR}/code_*)
167                         OPTS="$OPTS -r"
168                         TYPE="$TYPE .code.c"
169                         prefix=`echo "$prefix" | sed -e 's/^code_//'`
170                         ;;
171                 ${TEST_DIR}/pure_*)
172                         OPTS="$OPTS -P"
173                         prefix=`echo "$prefix" | sed -e 's/^pure_//'`
174                         ;;
175                 ${TEST_DIR}/quote_*)
176                         OPT2="-s"
177                         ;;
178                 ${TEST_DIR}/inherit*|\
179                 ${TEST_DIR}/err_inherit*)
180                         if test $ifBTYACC = 0; then continue; fi
181                         ;;
182                 esac
183
184                 echo "** testing $input"
185
186                 test -n "$prefix" && prefix="-p $prefix"
187
188                 for opt2 in "" $OPT2
189                 do
190                         output=$OOPT
191                         if test -n "$output"
192                         then
193                                 output="-o $output"
194                                 error=`basename $OOPT .c`.error
195                         else
196                                 error=${ROOT}${opt2}.error
197                         fi
198
199                         $YACC $OPTS $opt2 -v -d $output $prefix -b $ROOT${opt2} $input 2>$error
200                         for type in $TYPE
201                         do
202                                 REF=${REF_DIR}/${root}${opt2}${type}
203
204                                 # handle renaming due to "-o" option
205                                 if test -n "$OOPT"
206                                 then
207                                         case $type in
208                                         *.tab.c)
209                                                 type=.c
210                                                 ;;
211                                         *.tab.h)
212                                                 type=.h
213                                                 ;;
214                                         *)
215                                                 ;;
216                                         esac
217                                         NEW=`basename $OOPT .c`${type}
218                                         case $NEW in
219                                         test-*)
220                                                 ;;
221                                         *)
222                                                 if test -f "$NEW"
223                                                 then
224                                                         REF=${REF_DIR}/$NEW
225                                                         mv $NEW test-$NEW
226                                                         NEW=test-$NEW
227                                                 fi
228                                                 ;;
229                                         esac
230                                 else
231                                         NEW=${ROOT}${opt2}${type}
232                                 fi
233                                 test_diffs
234                         done
235                 done
236                 ;;
237         esac
238 done