]> git.saurik.com Git - bison.git/blob - tests/regression.at
2a60d27ced97f5efe06a308c2b83ce810305d575
[bison.git] / tests / regression.at
1 # Bison Regressions. -*- Autotest -*-
2 # Copyright 2001 Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
7 # any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17 # 02111-1307, USA.
18
19 AT_BANNER([[Regression tests.]])
20
21 ## ------------------ ##
22 ## Duplicate string. ##
23 ## ------------------ ##
24
25
26 AT_SETUP([Duplicate string])
27
28 AT_DATA([duplicate.y],
29 [[/* `Bison -v' used to dump core when two tokens are defined with the same
30 string, as LE and GE below. */
31
32 %token NUM
33 %token LE "<="
34 %token GE "<="
35
36 %%
37 exp: '(' exp ')' | NUM ;
38 %%
39 ]])
40
41 AT_CHECK([bison -v duplicate.y -o duplicate.c], 0, ignore, ignore)
42
43 AT_CLEANUP([duplicate.*])
44
45
46 ## ----------- ##
47 ## Conflicts. ##
48 ## ----------- ##
49
50 AT_SETUP([Conflicts])
51
52 AT_DATA([input.y],
53 [[%token NUM OP
54 %%
55 exp: exp OP exp | NUM;
56 ]])
57
58 AT_CHECK([bison input.y -o input.c -v], 0, [],
59 [input.y contains 1 shift/reduce conflict.
60 ])
61
62 # Check the contents of the report.
63 AT_CHECK([cat input.output], [],
64 [[State 4 contains 1 shift/reduce conflict.
65
66 Grammar
67
68 rule 1 exp -> exp OP exp
69 rule 2 exp -> NUM
70
71 Terminals, with rules where they appear
72
73 $ (-1)
74 error (256)
75 NUM (257) 2
76 OP (258) 1
77
78 Nonterminals, with rules where they appear
79
80 exp (5)
81 on left: 1 2, on right: 1
82
83
84 state 0
85
86 NUM shift, and go to state 1
87
88 exp go to state 2
89
90
91
92 state 1
93
94 exp -> NUM . (rule 2)
95
96 $default reduce using rule 2 (exp)
97
98
99
100 state 2
101
102 exp -> exp . OP exp (rule 1)
103
104 $ go to state 5
105 OP shift, and go to state 3
106
107
108
109 state 3
110
111 exp -> exp OP . exp (rule 1)
112
113 NUM shift, and go to state 1
114
115 exp go to state 4
116
117
118
119 state 4
120
121 exp -> exp . OP exp (rule 1)
122 exp -> exp OP exp . (rule 1)
123
124 OP shift, and go to state 3
125
126 OP [reduce using rule 1 (exp)]
127 $default reduce using rule 1 (exp)
128
129
130
131 state 5
132
133 $ go to state 6
134
135
136
137 state 6
138
139 $default accept
140 ]])
141
142 AT_CLEANUP(input.c input.output)
143
144
145 ## ---------------------- ##
146 ## Mixing %token styles. ##
147 ## ---------------------- ##
148
149
150 AT_SETUP([Mixing %token styles])
151
152 # Taken from the documentation.
153 AT_DATA([input.y],
154 [[%token <operator> OR "||"
155 %token <operator> LE 134 "<="
156 %left OR "<="
157 %%
158 exp: ;
159 %%
160 ]])
161
162 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
163
164 AT_CLEANUP([input.*])
165
166
167
168 ## ---------------------- ##
169 ## %union and --defines. ##
170 ## ---------------------- ##
171
172
173 AT_SETUP([%union and --defines])
174
175 AT_DATA([union.y],
176 [%union
177 {
178 int integer;
179 char *string ;
180 }
181 %%
182 exp: {};
183 ])
184
185 AT_CHECK([bison --defines union.y])
186
187 AT_CLEANUP([union.*])
188
189
190 ## --------------------------------------- ##
191 ## Duplicate '/' in C comments in %union ##
192 ## --------------------------------------- ##
193
194
195 AT_SETUP([%union and C comments])
196
197 AT_DATA([union-comment.y],
198 [%union
199 {
200 /* The int. */ int integer;
201 /* The string. */ char *string ;
202 }
203 %%
204 exp: {};
205 ])
206
207 AT_CHECK([bison union-comment.y])
208 AT_CHECK([fgrep '//*' union-comment.tab.c], [1], [])
209
210 AT_CLEANUP([union-comment.*])
211
212
213 ## ----------------- ##
214 ## Invalid input 1. ##
215 ## ----------------- ##
216
217
218 AT_SETUP([Invalid input: 1])
219
220 AT_DATA([input.y],
221 [[%%
222 ?
223 ]])
224
225 AT_CHECK([bison input.y], [1], [],
226 [input.y:2: invalid input: `?'
227 input.y:3: fatal error: no rules in the input grammar
228 ])
229
230 AT_CLEANUP
231
232
233 ## ----------------- ##
234 ## Invalid input 2. ##
235 ## ----------------- ##
236
237
238 AT_SETUP([Invalid input: 2])
239
240 AT_DATA([input.y],
241 [[%%
242 default: 'a' }
243 ]])
244
245 AT_CHECK([bison input.y], [1], [],
246 [input.y:2: invalid input: `}'
247 ])
248
249 AT_CLEANUP
250
251
252
253 ## --------------------- ##
254 ## Invalid CPP headers. ##
255 ## --------------------- ##
256
257 # AT_TEST_CPP_GUARD_H([INPUT-FILE-BASE)
258 # -------------------------------------
259 m4_define([AT_TEST_CPP_GUARD_H],
260 [AT_SETUP([Invalid CPP guards: $1])
261
262 # possibly create and nuke inner directories.
263 m4_bmatch([$1], [[/]],
264 [dirname=`AS_DIRNAME([$1])`
265 AS_MKDIR_P([$dirname])
266 AT_CLEANUP_FILES([$dirname])])
267
268 AT_DATA([$1.y],
269 [%%
270 dummy:
271 ])
272
273 AT_CHECK([bison --defines=$1.h $1.y])
274
275 # CPP should be happy with it.
276 AT_CHECK([$CC -E $1.h], 0, [ignore])
277
278 AT_CLEANUP($1.*)
279 ])
280
281 AT_TEST_CPP_GUARD_H([input/input])
282 AT_TEST_CPP_GUARD_H([9foo])