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.
72 Terminals, with rules where they appear
79 Nonterminals, with rules where they appear
82 on left: 1 2, on right: 1
87 NUM shift, and go to state 1
97 $default reduce using rule 2 (exp)
103 exp -> exp . OP exp (rule 1)
106 OP shift, and go to state 3
112 exp -> exp OP . exp (rule 1)
114 NUM shift, and go to state 1
122 exp -> exp . OP exp (rule 1)
123 exp -> exp OP exp . (rule 1)
125 OP shift, and go to state 3
127 OP [reduce using rule 1 (exp)]
128 $default reduce using rule 1 (exp)
146 ## --------------------- ##
147 ## Solved SR Conflicts. ##
148 ## --------------------- ##
150 AT_SETUP([Solved SR Conflicts])
156 exp: exp OP exp | NUM;
159 AT_CHECK([bison input.y -o input.c -v], 0, [], [])
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.
168 1 4 exp -> exp OP exp
171 Terminals, with rules where they appear
178 Nonterminals, with rules where they appear
181 on left: 1 2, on right: 1
186 NUM shift, and go to state 1
194 exp -> NUM . (rule 2)
196 $default reduce using rule 2 (exp)
202 exp -> exp . OP exp (rule 1)
205 OP shift, and go to state 3
211 exp -> exp OP . exp (rule 1)
213 NUM shift, and go to state 1
221 exp -> exp . OP exp (rule 1)
222 exp -> exp OP exp . (rule 1)
224 OP shift, and go to state 3
226 $default reduce using rule 1 (exp)
246 ## ------------------- ##
247 ## Rule Line Numbers. ##
248 ## ------------------- ##
250 AT_SETUP([Rule Line Numbers])
282 AT_CHECK([bison input.y -o input.c -v], 0, [], [])
284 # Check the contents of the report.
285 AT_CHECK([cat input.output], [],
290 1 2 @1 -> /* empty */
291 2 2 expr -> 'a' @1 'b'
292 3 15 @2 -> /* empty */
295 Terminals, with rules where they appear
303 Nonterminals, with rules where they appear
308 on left: 1, on right: 2
310 on left: 3, on right: 4
315 'a' shift, and go to state 1
317 $default reduce using rule 3 (@2)
326 expr -> 'a' . @1 'b' (rule 2)
328 $default reduce using rule 1 (@1)
336 expr -> @2 . 'c' (rule 4)
338 'c' shift, and go to state 4
344 expr -> 'a' @1 . 'b' (rule 2)
346 'b' shift, and go to state 5
352 expr -> @2 'c' . (rule 4)
354 $default reduce using rule 4 (expr)
360 expr -> 'a' @1 'b' . (rule 2)
362 $default reduce using rule 2 (expr)
387 ## -------------------- ##
388 ## %expect not enough. ##
389 ## -------------------- ##
391 AT_SETUP([%expect not enough])
397 exp: exp OP exp | NUM;
400 AT_CHECK([bison input.y -o input.c], 1, [],
401 [input.y contains 1 shift/reduce conflict.
402 expected 0 shift/reduce conflicts
407 ## --------------- ##
409 ## --------------- ##
411 AT_SETUP([%expect right])
417 exp: exp OP exp | NUM;
420 AT_CHECK([bison input.y -o input.c], 0)
424 ## ------------------ ##
425 ## %expect too much. ##
426 ## ------------------ ##
428 AT_SETUP([%expect too much])
434 exp: exp OP exp | NUM;
437 AT_CHECK([bison input.y -o input.c], 1, [],
438 [input.y contains 1 shift/reduce conflict.
439 expected 2 shift/reduce conflicts
444 ## ---------------------- ##
445 ## Mixing %token styles. ##
446 ## ---------------------- ##
449 AT_SETUP([Mixing %token styles])
451 # Taken from the documentation.
453 [[%token <operator> OR "||"
454 %token <operator> LE 134 "<="
461 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
467 ## ---------------------- ##
468 ## %union and --defines. ##
469 ## ---------------------- ##
472 AT_SETUP([%union and --defines])
484 AT_CHECK([bison --defines union.y])
489 ## --------------------------------------- ##
490 ## Duplicate '/' in C comments in %union ##
491 ## --------------------------------------- ##
494 AT_SETUP([%union and C comments])
496 AT_DATA([union-comment.y],
499 /* The int. */ int integer;
500 /* The string. */ char *string ;
506 AT_CHECK([bison union-comment.y])
507 AT_CHECK([fgrep '//*' union-comment.tab.c], [1], [])
512 ## ----------------- ##
513 ## Invalid input 1. ##
514 ## ----------------- ##
517 AT_SETUP([Invalid input: 1])
524 AT_CHECK([bison input.y], [1], [],
525 [[input.y:2: invalid input: `?'
526 input.y:3: fatal error: no rules in the input grammar
532 ## ----------------- ##
533 ## Invalid input 2. ##
534 ## ----------------- ##
537 AT_SETUP([Invalid input: 2])
544 AT_CHECK([bison input.y], [1], [],
545 [[input.y:2: invalid input: `}'
552 ## -------------------- ##
553 ## Invalid %directive. ##
554 ## -------------------- ##
557 AT_SETUP([Invalid %directive])
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
573 ## --------------------- ##
574 ## Invalid CPP headers. ##
575 ## --------------------- ##
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])
582 # Possibly create inner directories.
583 dirname=`AS_DIRNAME([$1])`
584 AS_MKDIR_P([$dirname])
591 AT_CHECK([bison --defines=$1.h $1.y])
593 # CPP should be happy with it.
594 AT_CHECK([$CC -E $1.h], 0, [ignore])
599 AT_TEST_CPP_GUARD_H([input/input])
600 AT_TEST_CPP_GUARD_H([9foo])