]>
Commit | Line | Data |
---|---|---|
342b8b6e AD |
1 | # Bison Regressions. -*- Autotest -*- |
2 | # Copyright 2001 Free Software Foundation, Inc. | |
c95f2d78 | 3 | |
342b8b6e AD |
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. | |
c95f2d78 | 8 | |
342b8b6e AD |
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. | |
c95f2d78 | 13 | |
342b8b6e AD |
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. | |
c95f2d78 | 18 | |
342b8b6e | 19 | AT_BANNER([[Regression tests.]]) |
c95f2d78 AD |
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 | ||
d803322e | 43 | AT_CLEANUP |
c95f2d78 AD |
44 | |
45 | ||
ba9dda1a AD |
46 | ## ------------------------- ## |
47 | ## Unresolved SR Conflicts. ## | |
48 | ## ------------------------- ## | |
0df87bb6 | 49 | |
ba9dda1a | 50 | AT_SETUP([Unresolved SR Conflicts]) |
0df87bb6 AD |
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 | ||
b29b2ed5 AD |
68 | Number, Line, Rule |
69 | 1 3 exp -> exp OP exp | |
70 | 2 3 exp -> NUM | |
0df87bb6 AD |
71 | |
72 | Terminals, with rules where they appear | |
73 | ||
74 | $ (-1) | |
75 | error (256) | |
76 | NUM (257) 2 | |
77 | OP (258) 1 | |
78 | ||
79 | Nonterminals, with rules where they appear | |
80 | ||
81 | exp (5) | |
82 | on left: 1 2, on right: 1 | |
83 | ||
84 | ||
85 | state 0 | |
86 | ||
87 | NUM shift, and go to state 1 | |
88 | ||
89 | exp go to state 2 | |
90 | ||
91 | ||
92 | ||
93 | state 1 | |
94 | ||
95 | exp -> NUM . (rule 2) | |
96 | ||
97 | $default reduce using rule 2 (exp) | |
98 | ||
99 | ||
100 | ||
101 | state 2 | |
102 | ||
103 | exp -> exp . OP exp (rule 1) | |
104 | ||
105 | $ go to state 5 | |
106 | OP shift, and go to state 3 | |
107 | ||
108 | ||
109 | ||
110 | state 3 | |
111 | ||
112 | exp -> exp OP . exp (rule 1) | |
113 | ||
114 | NUM shift, and go to state 1 | |
115 | ||
116 | exp go to state 4 | |
117 | ||
118 | ||
119 | ||
120 | state 4 | |
121 | ||
122 | exp -> exp . OP exp (rule 1) | |
123 | exp -> exp OP exp . (rule 1) | |
124 | ||
125 | OP shift, and go to state 3 | |
126 | ||
c73a41af AD |
127 | OP [reduce using rule 1 (exp)] |
128 | $default reduce using rule 1 (exp) | |
129 | ||
0df87bb6 AD |
130 | |
131 | ||
132 | state 5 | |
133 | ||
134 | $ go to state 6 | |
135 | ||
136 | ||
137 | ||
ba9dda1a AD |
138 | state 6 |
139 | ||
140 | $default accept | |
141 | ]]) | |
142 | ||
d803322e | 143 | AT_CLEANUP |
ba9dda1a AD |
144 | |
145 | ||
146 | ## --------------------- ## | |
147 | ## Solved SR Conflicts. ## | |
148 | ## --------------------- ## | |
149 | ||
150 | AT_SETUP([Solved SR Conflicts]) | |
151 | ||
152 | AT_DATA([input.y], | |
153 | [[%token NUM OP | |
154 | %right OP | |
155 | %% | |
156 | exp: exp OP exp | NUM; | |
157 | ]]) | |
158 | ||
159 | AT_CHECK([bison input.y -o input.c -v], 0, [], []) | |
160 | ||
161 | # Check the contents of the report. | |
162 | AT_CHECK([cat input.output], [], | |
163 | [[Conflict in state 4 between rule 1 and token OP resolved as shift. | |
164 | ||
165 | Grammar | |
166 | ||
b29b2ed5 AD |
167 | Number, Line, Rule |
168 | 1 4 exp -> exp OP exp | |
169 | 2 4 exp -> NUM | |
ba9dda1a AD |
170 | |
171 | Terminals, with rules where they appear | |
172 | ||
173 | $ (-1) | |
174 | error (256) | |
175 | NUM (257) 2 | |
176 | OP (258) 1 | |
177 | ||
178 | Nonterminals, with rules where they appear | |
179 | ||
180 | exp (5) | |
181 | on left: 1 2, on right: 1 | |
182 | ||
183 | ||
184 | state 0 | |
185 | ||
186 | NUM shift, and go to state 1 | |
187 | ||
188 | exp go to state 2 | |
189 | ||
190 | ||
191 | ||
192 | state 1 | |
193 | ||
194 | exp -> NUM . (rule 2) | |
195 | ||
196 | $default reduce using rule 2 (exp) | |
197 | ||
198 | ||
199 | ||
200 | state 2 | |
201 | ||
202 | exp -> exp . OP exp (rule 1) | |
203 | ||
204 | $ go to state 5 | |
205 | OP shift, and go to state 3 | |
206 | ||
207 | ||
208 | ||
209 | state 3 | |
210 | ||
211 | exp -> exp OP . exp (rule 1) | |
212 | ||
213 | NUM shift, and go to state 1 | |
214 | ||
215 | exp go to state 4 | |
216 | ||
217 | ||
218 | ||
219 | state 4 | |
220 | ||
221 | exp -> exp . OP exp (rule 1) | |
222 | exp -> exp OP exp . (rule 1) | |
223 | ||
224 | OP shift, and go to state 3 | |
225 | ||
226 | $default reduce using rule 1 (exp) | |
227 | ||
228 | ||
229 | ||
230 | state 5 | |
231 | ||
232 | $ go to state 6 | |
233 | ||
234 | ||
235 | ||
0df87bb6 AD |
236 | state 6 |
237 | ||
238 | $default accept | |
239 | ]]) | |
240 | ||
d803322e | 241 | AT_CLEANUP |
0df87bb6 | 242 | |
c95f2d78 | 243 | |
7da99ede | 244 | |
2ca209c1 AD |
245 | |
246 | ## ------------------- ## | |
247 | ## Rule Line Numbers. ## | |
248 | ## ------------------- ## | |
249 | ||
250 | AT_SETUP([Rule Line Numbers]) | |
251 | ||
252 | AT_DATA([input.y], | |
253 | [[%% | |
254 | expr: | |
255 | 'a' | |
256 | ||
257 | { | |
258 | ||
259 | } | |
260 | ||
261 | 'b' | |
262 | ||
263 | { | |
264 | ||
265 | } | |
266 | ||
267 | | | |
268 | ||
269 | ||
270 | { | |
271 | ||
272 | ||
273 | } | |
274 | ||
275 | 'c' | |
276 | ||
277 | { | |
278 | ||
279 | } | |
280 | ]]) | |
281 | ||
282 | AT_CHECK([bison input.y -o input.c -v], 0, [], []) | |
283 | ||
284 | # Check the contents of the report. | |
285 | AT_CHECK([cat input.output], [], | |
286 | [[ | |
287 | Grammar | |
288 | ||
289 | Number, Line, Rule | |
290 | 1 2 @1 -> /* empty */ | |
291 | 2 2 expr -> 'a' @1 'b' | |
292 | 3 15 @2 -> /* empty */ | |
293 | 4 15 expr -> @2 'c' | |
294 | ||
295 | Terminals, with rules where they appear | |
296 | ||
297 | $ (-1) | |
298 | 'a' (97) 2 | |
299 | 'b' (98) 2 | |
300 | 'c' (99) 4 | |
301 | error (256) | |
302 | ||
303 | Nonterminals, with rules where they appear | |
304 | ||
305 | expr (6) | |
306 | on left: 2 4 | |
307 | @1 (7) | |
308 | on left: 1, on right: 2 | |
309 | @2 (8) | |
310 | on left: 3, on right: 4 | |
311 | ||
312 | ||
313 | state 0 | |
314 | ||
315 | 'a' shift, and go to state 1 | |
316 | ||
317 | $default reduce using rule 3 (@2) | |
318 | ||
319 | expr go to state 6 | |
320 | @2 go to state 2 | |
321 | ||
322 | ||
323 | ||
324 | state 1 | |
325 | ||
326 | expr -> 'a' . @1 'b' (rule 2) | |
327 | ||
328 | $default reduce using rule 1 (@1) | |
329 | ||
330 | @1 go to state 3 | |
331 | ||
332 | ||
333 | ||
334 | state 2 | |
335 | ||
336 | expr -> @2 . 'c' (rule 4) | |
337 | ||
338 | 'c' shift, and go to state 4 | |
339 | ||
340 | ||
341 | ||
342 | state 3 | |
343 | ||
344 | expr -> 'a' @1 . 'b' (rule 2) | |
345 | ||
346 | 'b' shift, and go to state 5 | |
347 | ||
348 | ||
349 | ||
350 | state 4 | |
351 | ||
352 | expr -> @2 'c' . (rule 4) | |
353 | ||
354 | $default reduce using rule 4 (expr) | |
355 | ||
356 | ||
357 | ||
358 | state 5 | |
359 | ||
360 | expr -> 'a' @1 'b' . (rule 2) | |
361 | ||
362 | $default reduce using rule 2 (expr) | |
363 | ||
364 | ||
365 | ||
366 | state 6 | |
367 | ||
368 | $ go to state 7 | |
369 | ||
370 | ||
371 | ||
372 | state 7 | |
373 | ||
374 | $ go to state 8 | |
375 | ||
376 | ||
377 | ||
378 | state 8 | |
379 | ||
380 | $default accept | |
381 | ]]) | |
382 | ||
383 | AT_CLEANUP | |
384 | ||
385 | ||
386 | ||
7da99ede AD |
387 | ## -------------------- ## |
388 | ## %expect not enough. ## | |
389 | ## -------------------- ## | |
390 | ||
391 | AT_SETUP([%expect not enough]) | |
392 | ||
393 | AT_DATA([input.y], | |
394 | [[%token NUM OP | |
395 | %expect 0 | |
396 | %% | |
397 | exp: exp OP exp | NUM; | |
398 | ]]) | |
399 | ||
400 | AT_CHECK([bison input.y -o input.c], 1, [], | |
401 | [input.y contains 1 shift/reduce conflict. | |
402 | expected 0 shift/reduce conflicts | |
403 | ]) | |
d803322e | 404 | AT_CLEANUP |
7da99ede AD |
405 | |
406 | ||
407 | ## --------------- ## | |
408 | ## %expect right. ## | |
409 | ## --------------- ## | |
410 | ||
411 | AT_SETUP([%expect right]) | |
412 | ||
413 | AT_DATA([input.y], | |
414 | [[%token NUM OP | |
415 | %expect 1 | |
416 | %% | |
417 | exp: exp OP exp | NUM; | |
418 | ]]) | |
419 | ||
a034c8b8 | 420 | AT_CHECK([bison input.y -o input.c], 0) |
d803322e | 421 | AT_CLEANUP |
7da99ede AD |
422 | |
423 | ||
424 | ## ------------------ ## | |
425 | ## %expect too much. ## | |
426 | ## ------------------ ## | |
427 | ||
428 | AT_SETUP([%expect too much]) | |
429 | ||
430 | AT_DATA([input.y], | |
431 | [[%token NUM OP | |
432 | %expect 2 | |
433 | %% | |
434 | exp: exp OP exp | NUM; | |
435 | ]]) | |
436 | ||
437 | AT_CHECK([bison input.y -o input.c], 1, [], | |
438 | [input.y contains 1 shift/reduce conflict. | |
439 | expected 2 shift/reduce conflicts | |
440 | ]) | |
d803322e | 441 | AT_CLEANUP |
7da99ede AD |
442 | |
443 | ||
cd5aafcf AD |
444 | ## ---------------------- ## |
445 | ## Mixing %token styles. ## | |
446 | ## ---------------------- ## | |
447 | ||
448 | ||
449 | AT_SETUP([Mixing %token styles]) | |
450 | ||
451 | # Taken from the documentation. | |
452 | AT_DATA([input.y], | |
453 | [[%token <operator> OR "||" | |
454 | %token <operator> LE 134 "<=" | |
455 | %left OR "<=" | |
456 | %% | |
457 | exp: ; | |
458 | %% | |
459 | ]]) | |
460 | ||
461 | AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore) | |
462 | ||
d803322e | 463 | AT_CLEANUP |
cd5aafcf AD |
464 | |
465 | ||
466 | ||
c95f2d78 AD |
467 | ## ---------------------- ## |
468 | ## %union and --defines. ## | |
469 | ## ---------------------- ## | |
470 | ||
471 | ||
472 | AT_SETUP([%union and --defines]) | |
473 | ||
474 | AT_DATA([union.y], | |
475 | [%union | |
476 | { | |
477 | int integer; | |
478 | char *string ; | |
479 | } | |
480 | %% | |
481 | exp: {}; | |
482 | ]) | |
483 | ||
484 | AT_CHECK([bison --defines union.y]) | |
485 | ||
d803322e | 486 | AT_CLEANUP |
342b8b6e AD |
487 | |
488 | ||
489 | ## --------------------------------------- ## | |
490 | ## Duplicate '/' in C comments in %union ## | |
491 | ## --------------------------------------- ## | |
492 | ||
493 | ||
494 | AT_SETUP([%union and C comments]) | |
495 | ||
496 | AT_DATA([union-comment.y], | |
497 | [%union | |
498 | { | |
499 | /* The int. */ int integer; | |
500 | /* The string. */ char *string ; | |
501 | } | |
502 | %% | |
503 | exp: {}; | |
504 | ]) | |
505 | ||
506 | AT_CHECK([bison union-comment.y]) | |
507 | AT_CHECK([fgrep '//*' union-comment.tab.c], [1], []) | |
508 | ||
d803322e | 509 | AT_CLEANUP |
342b8b6e AD |
510 | |
511 | ||
561f9a30 AD |
512 | ## ----------------- ## |
513 | ## Invalid input 1. ## | |
514 | ## ----------------- ## | |
515 | ||
516 | ||
517 | AT_SETUP([Invalid input: 1]) | |
518 | ||
519 | AT_DATA([input.y], | |
520 | [[%% | |
521 | ? | |
522 | ]]) | |
523 | ||
524 | AT_CHECK([bison input.y], [1], [], | |
e0c40012 | 525 | [[input.y:2: invalid input: `?' |
561f9a30 | 526 | input.y:3: fatal error: no rules in the input grammar |
e0c40012 | 527 | ]]) |
561f9a30 AD |
528 | |
529 | AT_CLEANUP | |
530 | ||
531 | ||
532 | ## ----------------- ## | |
533 | ## Invalid input 2. ## | |
534 | ## ----------------- ## | |
535 | ||
536 | ||
537 | AT_SETUP([Invalid input: 2]) | |
538 | ||
539 | AT_DATA([input.y], | |
540 | [[%% | |
541 | default: 'a' } | |
542 | ]]) | |
543 | ||
544 | AT_CHECK([bison input.y], [1], [], | |
e0c40012 AD |
545 | [[input.y:2: invalid input: `}' |
546 | ]]) | |
547 | ||
548 | AT_CLEANUP | |
549 | ||
550 | ||
551 | ||
552 | ## -------------------- ## | |
553 | ## Invalid %directive. ## | |
554 | ## -------------------- ## | |
555 | ||
556 | ||
557 | AT_SETUP([Invalid %directive]) | |
558 | ||
559 | AT_DATA([input.y], | |
560 | [[%invalid | |
561 | ]]) | |
562 | ||
563 | AT_CHECK([bison input.y], [1], [], | |
564 | [[input.y:1: unrecognized: %invalid | |
565 | input.y:1: Skipping to next % | |
566 | input.y:2: fatal error: no input grammar | |
567 | ]]) | |
561f9a30 AD |
568 | |
569 | AT_CLEANUP | |
570 | ||
571 | ||
270a173c | 572 | |
342b8b6e AD |
573 | ## --------------------- ## |
574 | ## Invalid CPP headers. ## | |
575 | ## --------------------- ## | |
576 | ||
270a173c AD |
577 | # AT_TEST_CPP_GUARD_H([INPUT-FILE-BASE) |
578 | # ------------------------------------- | |
579 | m4_define([AT_TEST_CPP_GUARD_H], | |
580 | [AT_SETUP([Invalid CPP guards: $1]) | |
342b8b6e | 581 | |
d803322e AD |
582 | # Possibly create inner directories. |
583 | dirname=`AS_DIRNAME([$1])` | |
270a173c | 584 | AS_MKDIR_P([$dirname]) |
342b8b6e | 585 | |
270a173c | 586 | AT_DATA([$1.y], |
342b8b6e AD |
587 | [%% |
588 | dummy: | |
589 | ]) | |
590 | ||
270a173c | 591 | AT_CHECK([bison --defines=$1.h $1.y]) |
342b8b6e | 592 | |
270a173c AD |
593 | # CPP should be happy with it. |
594 | AT_CHECK([$CC -E $1.h], 0, [ignore]) | |
595 | ||
d803322e | 596 | AT_CLEANUP |
270a173c | 597 | ]) |
342b8b6e | 598 | |
270a173c AD |
599 | AT_TEST_CPP_GUARD_H([input/input]) |
600 | AT_TEST_CPP_GUARD_H([9foo]) |