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)
43 AT_CLEANUP([duplicate.*])
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.
68 rule 1 exp -> exp OP exp
71 Terminals, with rules where they appear
78 Nonterminals, with rules where they appear
81 on left: 1 2, on right: 1
86 NUM shift, and go to state 1
96 $default reduce using rule 2 (exp)
102 exp -> exp . OP exp (rule 1)
105 OP shift, and go to state 3
111 exp -> exp OP . exp (rule 1)
113 NUM shift, and go to state 1
121 exp -> exp . OP exp (rule 1)
122 exp -> exp OP exp . (rule 1)
124 OP shift, and go to state 3
126 OP [reduce using rule 1 (exp)]
127 $default reduce using rule 1 (exp)
142 AT_CLEANUP(input.c input.output)
145 ## --------------------- ##
146 ## Solved SR Conflicts. ##
147 ## --------------------- ##
149 AT_SETUP([Solved SR Conflicts])
155 exp: exp OP exp | NUM;
158 AT_CHECK([bison input.y -o input.c -v], 0, [], [])
160 # Check the contents of the report.
161 AT_CHECK([cat input.output], [],
162 [[Conflict in state 4 between rule 1 and token OP resolved as shift.
166 rule 1 exp -> exp OP exp
169 Terminals, with rules where they appear
176 Nonterminals, with rules where they appear
179 on left: 1 2, on right: 1
184 NUM shift, and go to state 1
192 exp -> NUM . (rule 2)
194 $default reduce using rule 2 (exp)
200 exp -> exp . OP exp (rule 1)
203 OP shift, and go to state 3
209 exp -> exp OP . exp (rule 1)
211 NUM shift, and go to state 1
219 exp -> exp . OP exp (rule 1)
220 exp -> exp OP exp . (rule 1)
222 OP shift, and go to state 3
224 $default reduce using rule 1 (exp)
239 AT_CLEANUP(input.c input.output)
242 ## ---------------------- ##
243 ## Mixing %token styles. ##
244 ## ---------------------- ##
247 AT_SETUP([Mixing %token styles])
249 # Taken from the documentation.
251 [[%token <operator> OR "||"
252 %token <operator> LE 134 "<="
259 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
261 AT_CLEANUP([input.*])
265 ## ---------------------- ##
266 ## %union and --defines. ##
267 ## ---------------------- ##
270 AT_SETUP([%union and --defines])
282 AT_CHECK([bison --defines union.y])
284 AT_CLEANUP([union.*])
287 ## --------------------------------------- ##
288 ## Duplicate '/' in C comments in %union ##
289 ## --------------------------------------- ##
292 AT_SETUP([%union and C comments])
294 AT_DATA([union-comment.y],
297 /* The int. */ int integer;
298 /* The string. */ char *string ;
304 AT_CHECK([bison union-comment.y])
305 AT_CHECK([fgrep '//*' union-comment.tab.c], [1], [])
307 AT_CLEANUP([union-comment.*])
310 ## ----------------- ##
311 ## Invalid input 1. ##
312 ## ----------------- ##
315 AT_SETUP([Invalid input: 1])
322 AT_CHECK([bison input.y], [1], [],
323 [input.y:2: invalid input: `?'
324 input.y:3: fatal error: no rules in the input grammar
330 ## ----------------- ##
331 ## Invalid input 2. ##
332 ## ----------------- ##
335 AT_SETUP([Invalid input: 2])
342 AT_CHECK([bison input.y], [1], [],
343 [input.y:2: invalid input: `}'
350 ## --------------------- ##
351 ## Invalid CPP headers. ##
352 ## --------------------- ##
354 # AT_TEST_CPP_GUARD_H([INPUT-FILE-BASE)
355 # -------------------------------------
356 m4_define([AT_TEST_CPP_GUARD_H],
357 [AT_SETUP([Invalid CPP guards: $1])
359 # possibly create and nuke inner directories.
360 m4_bmatch([$1], [[/]],
361 [dirname=`AS_DIRNAME([$1])`
362 AS_MKDIR_P([$dirname])
363 AT_CLEANUP_FILES([$dirname])])
370 AT_CHECK([bison --defines=$1.h $1.y])
372 # CPP should be happy with it.
373 AT_CHECK([$CC -E $1.h], 0, [ignore])
378 AT_TEST_CPP_GUARD_H([input/input])
379 AT_TEST_CPP_GUARD_H([9foo])