1 # Bison Regressions. -*- Autotest -*-
2 # Copyright 2001 Free Software Foundation, Inc.
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)
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.
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
19 AT_BANNER([[Regression tests.]])
21 ## ------------------ ##
22 ## Duplicate string. ##
23 ## ------------------ ##
26 AT_SETUP([Duplicate string])
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. */
37 exp: '(' exp ')' | NUM ;
41 AT_CHECK([bison -v duplicate.y -o duplicate.c], 0, ignore, ignore)
46 ## ------------------------- ##
47 ## Unresolved SR Conflicts. ##
48 ## ------------------------- ##
50 AT_SETUP([Unresolved SR Conflicts])
55 exp: exp OP exp | NUM;
58 AT_CHECK([bison input.y -o input.c -v], 0, [],
59 [input.y contains 1 shift/reduce conflict.
62 # Check the contents of the report.
63 AT_CHECK([cat input.output], [],
64 [[State 4 contains 1 shift/reduce conflict.
74 Terminals, with rules where they appear
82 Nonterminals, with rules where they appear
85 on left: 1 2, on right: 1
90 NUM shift, and go to state 1
100 $default reduce using rule 2 (exp)
106 exp -> exp . OP exp (rule 1)
108 $ shift, and go to state 5
109 OP shift, and go to state 3
115 exp -> exp OP . exp (rule 1)
117 NUM shift, and go to state 1
125 exp -> exp . OP exp (rule 1)
126 exp -> exp OP exp . (rule 1)
128 OP shift, and go to state 3
130 OP [reduce using rule 1 (exp)]
131 $default reduce using rule 1 (exp)
137 $ shift, and go to state 6
151 ## --------------------- ##
152 ## Solved SR Conflicts. ##
153 ## --------------------- ##
155 AT_SETUP([Solved SR Conflicts])
161 exp: exp OP exp | NUM;
164 AT_CHECK([bison input.y -o input.c -v], 0, [], [])
166 # Check the contents of the report.
167 AT_CHECK([cat input.output], [],
168 [[Conflict in state 4 between rule 1 and token OP resolved as shift.
174 1 4 exp -> exp OP exp
178 Terminals, with rules where they appear
186 Nonterminals, with rules where they appear
189 on left: 1 2, on right: 1
194 NUM shift, and go to state 1
202 exp -> NUM . (rule 2)
204 $default reduce using rule 2 (exp)
210 exp -> exp . OP exp (rule 1)
212 $ shift, and go to state 5
213 OP shift, and go to state 3
219 exp -> exp OP . exp (rule 1)
221 NUM shift, and go to state 1
229 exp -> exp . OP exp (rule 1)
230 exp -> exp OP exp . (rule 1)
232 OP shift, and go to state 3
234 $default reduce using rule 1 (exp)
240 $ shift, and go to state 6
256 ## ------------------- ##
257 ## Rule Line Numbers. ##
258 ## ------------------- ##
260 AT_SETUP([Rule Line Numbers])
292 AT_CHECK([bison input.y -o input.c -v], 0, [], [])
294 # Check the contents of the report.
295 AT_CHECK([cat input.output], [],
299 1 2 @1 -> /* empty */
300 2 2 expr -> 'a' @1 'b'
301 3 15 @2 -> /* empty */
305 Terminals, with rules where they appear
314 Nonterminals, with rules where they appear
319 on left: 1, on right: 2
321 on left: 3, on right: 4
326 'a' shift, and go to state 1
328 $default reduce using rule 3 (@2)
337 expr -> 'a' . @1 'b' (rule 2)
339 $default reduce using rule 1 (@1)
347 expr -> @2 . 'c' (rule 4)
349 'c' shift, and go to state 4
355 expr -> 'a' @1 . 'b' (rule 2)
357 'b' shift, and go to state 5
363 expr -> @2 'c' . (rule 4)
365 $default reduce using rule 4 (expr)
371 expr -> 'a' @1 'b' . (rule 2)
373 $default reduce using rule 2 (expr)
379 $ shift, and go to state 7
394 ## -------------------- ##
395 ## %expect not enough. ##
396 ## -------------------- ##
398 AT_SETUP([%expect not enough])
404 exp: exp OP exp | NUM;
407 AT_CHECK([bison input.y -o input.c], 1, [],
408 [input.y contains 1 shift/reduce conflict.
409 expected 0 shift/reduce conflicts
414 ## --------------- ##
416 ## --------------- ##
418 AT_SETUP([%expect right])
424 exp: exp OP exp | NUM;
427 AT_CHECK([bison input.y -o input.c], 0)
431 ## ------------------ ##
432 ## %expect too much. ##
433 ## ------------------ ##
435 AT_SETUP([%expect too much])
441 exp: exp OP exp | NUM;
444 AT_CHECK([bison input.y -o input.c], 1, [],
445 [input.y contains 1 shift/reduce conflict.
446 expected 2 shift/reduce conflicts
451 ## ---------------------- ##
452 ## Mixing %token styles. ##
453 ## ---------------------- ##
456 AT_SETUP([Mixing %token styles])
458 # Taken from the documentation.
460 [[%token <operator> OR "||"
461 %token <operator> LE 134 "<="
468 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
474 ## ---------------------- ##
475 ## %union and --defines. ##
476 ## ---------------------- ##
479 AT_SETUP([%union and --defines])
491 AT_CHECK([bison --defines union.y])
496 ## --------------------------------------- ##
497 ## Duplicate '/' in C comments in %union ##
498 ## --------------------------------------- ##
501 AT_SETUP([%union and C comments])
503 AT_DATA([union-comment.y],
506 /* The int. */ int integer;
507 /* The string. */ char *string ;
513 AT_CHECK([bison union-comment.y])
514 AT_CHECK([fgrep '//*' union-comment.tab.c], [1], [])
519 ## ----------------- ##
520 ## Invalid input 1. ##
521 ## ----------------- ##
524 AT_SETUP([Invalid input: 1])
531 AT_CHECK([bison input.y], [1], [],
532 [[input.y:2: invalid input: `?'
533 input.y:3: fatal error: no rules in the input grammar
539 ## ----------------- ##
540 ## Invalid input 2. ##
541 ## ----------------- ##
544 AT_SETUP([Invalid input: 2])
551 AT_CHECK([bison input.y], [1], [],
552 [[input.y:2: invalid input: `}'
559 ## -------------------- ##
560 ## Invalid %directive. ##
561 ## -------------------- ##
564 AT_SETUP([Invalid %directive])
570 AT_CHECK([bison input.y], [1], [],
571 [[input.y:1: unrecognized: %invalid
572 input.y:1: Skipping to next %
573 input.y:2: fatal error: no input grammar
580 ## --------------------- ##
581 ## Invalid CPP headers. ##
582 ## --------------------- ##
584 # AT_TEST_CPP_GUARD_H([INPUT-FILE-BASE)
585 # -------------------------------------
586 m4_define([AT_TEST_CPP_GUARD_H],
587 [AT_SETUP([Invalid CPP guards: $1])
589 # Possibly create inner directories.
590 dirname=`AS_DIRNAME([$1])`
591 AS_MKDIR_P([$dirname])
598 AT_CHECK([bison --defines=$1.h $1.y])
600 # CPP should be happy with it.
601 AT_CHECK([$CC -E $1.h], 0, [ignore])
606 AT_TEST_CPP_GUARD_H([input/input])
607 AT_TEST_CPP_GUARD_H([9foo])
610 ## ---------------- ##
611 ## Broken Closure. ##
612 ## ---------------- ##
614 # TC was once broken during a massive `simplification' of the code.
615 # It resulted in bison dumping core on the following grammar (the
616 # computation of FIRSTS uses TC). It managed to produce a pretty
647 # instead of that below.
649 AT_SETUP([Broken Closure])
663 AT_CHECK([bison --trace input.y 2>&1 |
664 sed -n '/^TC: Output BEGIN/,/^TC: Output END/p'],