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)
243 ## -------------------- ##
244 ## %expect not enough. ##
245 ## -------------------- ##
247 AT_SETUP([%expect not enough])
253 exp: exp OP exp | NUM;
256 AT_CHECK([bison input.y -o input.c], 1, [],
257 [input.y contains 1 shift/reduce conflict.
258 expected 0 shift/reduce conflicts
263 ## --------------- ##
265 ## --------------- ##
267 AT_SETUP([%expect right])
273 exp: exp OP exp | NUM;
276 AT_CHECK([bison input.y -o input.c], 0, [],
277 [input.y contains 1 shift/reduce conflict.
282 ## ------------------ ##
283 ## %expect too much. ##
284 ## ------------------ ##
286 AT_SETUP([%expect too much])
292 exp: exp OP exp | NUM;
295 AT_CHECK([bison input.y -o input.c], 1, [],
296 [input.y contains 1 shift/reduce conflict.
297 expected 2 shift/reduce conflicts
302 ## ---------------------- ##
303 ## Mixing %token styles. ##
304 ## ---------------------- ##
307 AT_SETUP([Mixing %token styles])
309 # Taken from the documentation.
311 [[%token <operator> OR "||"
312 %token <operator> LE 134 "<="
319 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
321 AT_CLEANUP([input.*])
325 ## ---------------------- ##
326 ## %union and --defines. ##
327 ## ---------------------- ##
330 AT_SETUP([%union and --defines])
342 AT_CHECK([bison --defines union.y])
344 AT_CLEANUP([union.*])
347 ## --------------------------------------- ##
348 ## Duplicate '/' in C comments in %union ##
349 ## --------------------------------------- ##
352 AT_SETUP([%union and C comments])
354 AT_DATA([union-comment.y],
357 /* The int. */ int integer;
358 /* The string. */ char *string ;
364 AT_CHECK([bison union-comment.y])
365 AT_CHECK([fgrep '//*' union-comment.tab.c], [1], [])
367 AT_CLEANUP([union-comment.*])
370 ## ----------------- ##
371 ## Invalid input 1. ##
372 ## ----------------- ##
375 AT_SETUP([Invalid input: 1])
382 AT_CHECK([bison input.y], [1], [],
383 [input.y:2: invalid input: `?'
384 input.y:3: fatal error: no rules in the input grammar
390 ## ----------------- ##
391 ## Invalid input 2. ##
392 ## ----------------- ##
395 AT_SETUP([Invalid input: 2])
402 AT_CHECK([bison input.y], [1], [],
403 [input.y:2: invalid input: `}'
410 ## --------------------- ##
411 ## Invalid CPP headers. ##
412 ## --------------------- ##
414 # AT_TEST_CPP_GUARD_H([INPUT-FILE-BASE)
415 # -------------------------------------
416 m4_define([AT_TEST_CPP_GUARD_H],
417 [AT_SETUP([Invalid CPP guards: $1])
419 # possibly create and nuke inner directories.
420 m4_bmatch([$1], [[/]],
421 [dirname=`AS_DIRNAME([$1])`
422 AS_MKDIR_P([$dirname])
423 AT_CLEANUP_FILES([$dirname])])
430 AT_CHECK([bison --defines=$1.h $1.y])
432 # CPP should be happy with it.
433 AT_CHECK([$CC -E $1.h], 0, [ignore])
438 AT_TEST_CPP_GUARD_H([input/input])
439 AT_TEST_CPP_GUARD_H([9foo])