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)
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)
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)
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)
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)
400 ## -------------------- ##
401 ## %expect not enough. ##
402 ## -------------------- ##
404 AT_SETUP([%expect not enough])
410 exp: exp OP exp | NUM;
413 AT_CHECK([bison input.y -o input.c], 1, [],
414 [input.y contains 1 shift/reduce conflict.
415 expected 0 shift/reduce conflicts
420 ## --------------- ##
422 ## --------------- ##
424 AT_SETUP([%expect right])
430 exp: exp OP exp | NUM;
433 AT_CHECK([bison input.y -o input.c], 0)
437 ## ------------------ ##
438 ## %expect too much. ##
439 ## ------------------ ##
441 AT_SETUP([%expect too much])
447 exp: exp OP exp | NUM;
450 AT_CHECK([bison input.y -o input.c], 1, [],
451 [input.y contains 1 shift/reduce conflict.
452 expected 2 shift/reduce conflicts
457 ## ---------------------- ##
458 ## Mixing %token styles. ##
459 ## ---------------------- ##
462 AT_SETUP([Mixing %token styles])
464 # Taken from the documentation.
466 [[%token <operator> OR "||"
467 %token <operator> LE 134 "<="
474 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
480 ## ---------------------- ##
481 ## %union and --defines. ##
482 ## ---------------------- ##
485 AT_SETUP([%union and --defines])
497 AT_CHECK([bison --defines union.y])
502 ## --------------------------------------- ##
503 ## Duplicate '/' in C comments in %union ##
504 ## --------------------------------------- ##
507 AT_SETUP([%union and C comments])
509 AT_DATA([union-comment.y],
512 /* The int. */ int integer;
513 /* The string. */ char *string ;
519 AT_CHECK([bison union-comment.y])
520 AT_CHECK([fgrep '//*' union-comment.tab.c], [1], [])
525 ## ----------------- ##
526 ## Invalid input 1. ##
527 ## ----------------- ##
530 AT_SETUP([Invalid input: 1])
537 AT_CHECK([bison input.y], [1], [],
538 [[input.y:2: invalid input: `?'
539 input.y:3: fatal error: no rules in the input grammar
545 ## ----------------- ##
546 ## Invalid input 2. ##
547 ## ----------------- ##
550 AT_SETUP([Invalid input: 2])
557 AT_CHECK([bison input.y], [1], [],
558 [[input.y:2: invalid input: `}'
565 ## -------------------- ##
566 ## Invalid %directive. ##
567 ## -------------------- ##
570 AT_SETUP([Invalid %directive])
576 AT_CHECK([bison input.y], [1], [],
577 [[input.y:1: unrecognized: %invalid
578 input.y:1: Skipping to next %
579 input.y:2: fatal error: no input grammar
586 ## --------------------- ##
587 ## Invalid CPP headers. ##
588 ## --------------------- ##
590 # AT_TEST_CPP_GUARD_H([INPUT-FILE-BASE)
591 # -------------------------------------
592 m4_define([AT_TEST_CPP_GUARD_H],
593 [AT_SETUP([Invalid CPP guards: $1])
595 # Possibly create inner directories.
596 dirname=`AS_DIRNAME([$1])`
597 AS_MKDIR_P([$dirname])
604 AT_CHECK([bison --defines=$1.h $1.y])
606 # CPP should be happy with it.
607 AT_CHECK([$CC -E $1.h], 0, [ignore])
612 AT_TEST_CPP_GUARD_H([input/input])
613 AT_TEST_CPP_GUARD_H([9foo])