]> git.saurik.com Git - bison.git/blame - tests/local.at
lalr1.cc: location_type: make sure we don't depend on loc.(begin|end).
[bison.git] / tests / local.at
CommitLineData
67a25fed
AD
1# Process this -*- Autotest -*- file with autom4te.
2
3# Macros for the GNU Bison Test suite.
e141f4d4 4# Copyright (C) 2003-2010 Free Software Foundation, Inc.
67a25fed 5
f16b0819 6# This program is free software: you can redistribute it and/or modify
67a25fed 7# it under the terms of the GNU General Public License as published by
f16b0819
PE
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
67a25fed
AD
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
f16b0819 15#
67a25fed 16# You should have received a copy of the GNU General Public License
f16b0819 17# along with this program. If not, see <http://www.gnu.org/licenses/>.
67a25fed 18
1f7a61ff 19# We want a recent Autotest.
ce05140d 20m4_version_prereq([2.58])
1f7a61ff 21
67a25fed 22
6617622c
AD
23## ------------- ##
24## Basic tests. ##
25## ------------- ##
26
27# AT_MATCHES_CHECK(FILE, PERL-REGEXP, COUNT)
28# ------------------------------------------
29# Expect COUNT matches of the PERL-REGEXP in FILE. The file is
30# taken in "slurp" mode, i.e., one can match end-of-lines.
31m4_define([AT_MATCHES_CHECK],
32[AT_CHECK([perl -0777 -ne '
33my $count = 0;
34s{$2}{ ++$count; "" }gem;
35printf "$count\n";' $1], [0], [$3
36])])
37
38
67a25fed
AD
39## ------------------------------- ##
40## Macros decoding Bison options. ##
41## ------------------------------- ##
42
4f756f88
AD
43# AT_LOC_PUSHDEF(FIRST-LINE, FIRST-COLUMN, LAST-LINE, LAST-COLUMN)
44# ----------------------------------------------------------------
45# Pushdef AT_LOC_(FIRST|LAST)_(LINE|COLUMN).
46m4_define([AT_LOC_PUSHDEF],
47[m4_pushdef([AT_LOC_FIRST_LINE], [AT_LOC.$1])
48m4_pushdef([AT_LOC_FIRST_COLUMN], [AT_LOC.$2])
49m4_pushdef([AT_LOC_LAST_LINE], [AT_LOC.$3])
50m4_pushdef([AT_LOC_LAST_COLUMN], [AT_LOC.$4])])
51
52# AT_LOC_POPDEF
53# -------------
54# Popdef AT_LOC_(FIRST|LAST)_(LINE|COL).
55m4_define([AT_LOC_POPDEF],
56[m4_popdef([AT_LOC_FIRST_LINE])
57m4_popdef([AT_LOC_FIRST_COLUMN])
58m4_popdef([AT_LOC_LAST_LINE])
59m4_popdef([AT_LOC_LAST_COLUMN])])
60
61
67a25fed
AD
62
63# AT_BISON_OPTION_PUSHDEFS([BISON-OPTIONS])
64# -----------------------------------------
65m4_define([AT_BISON_OPTION_PUSHDEFS],
66[_AT_BISON_OPTION_PUSHDEFS($[1], $[2], [$1])])
67
68
69# _AT_BISON_OPTION_PUSHDEFS($1, $2, [BISON-OPTIONS])
70# --------------------------------------------------
71# This macro works around the impossibility to define macros
72# inside macros, because issuing `[$1]' is not possible in M4 :(.
417e31d2 73# This sucks hard, GNU M4 should really provide M5-like $$1.
67a25fed
AD
74m4_define([_AT_BISON_OPTION_PUSHDEFS],
75[m4_if([$1$2], $[1]$[2], [],
76 [m4_fatal([$0: Invalid arguments: $@])])dnl
6c88b51e
JD
77m4_pushdef([AT_DEFINES_IF],
78[m4_bmatch([$3], [%defines], [$1], [$2])])
8f7e3cf9 79m4_pushdef([AT_SKEL_CC_IF],
0e021770 80[m4_bmatch([$3], [%language "[Cc]\+\+"\|%skeleton "[a-z0-9]+\.cc"], [$1], [$2])])
67a25fed 81m4_pushdef([AT_GLR_IF],
0e021770
PE
82[m4_bmatch([$3], [%glr-parser\|%skeleton "glr\.], [$1], [$2])])
83m4_pushdef([AT_LALR1_CC_IF],
84[AT_SKEL_CC_IF([AT_GLR_IF([$2], [$1])], [$2])])
85m4_pushdef([AT_GLR_CC_IF],
86[AT_SKEL_CC_IF([AT_GLR_IF([$1], [$2])], [$2])])
67a25fed
AD
87# Using yacc.c?
88m4_pushdef([AT_YACC_IF],
0e021770 89[m4_bmatch([$3], [%language\|%glr-parser\|%skeleton], [$2], [$1])])
01b477c6
PB
90m4_pushdef([AT_LEXPARAM_IF],
91[m4_bmatch([$3], [%lex-param], [$1], [$2])])
67a25fed
AD
92m4_pushdef([AT_LOCATION_IF],
93[m4_bmatch([$3], [%locations], [$1], [$2])])
24bb8c8c
AD
94m4_pushdef([AT_LOCATION_TYPE_IF],
95[m4_bmatch([$3], [%define location_type], [$1], [$2])])
96m4_pushdef([AT_PARAM_IF],
97[m4_bmatch([$3], [%parse-param], [$1], [$2])])
67a25fed 98m4_pushdef([AT_PURE_IF],
d9df47b6 99[m4_bmatch([$3], [%define *api\.pure\|%pure-parser],
cf499cff 100 [m4_bmatch([$3], [%define *api\.pure *"?false"?], [$2], [$1])],
d9df47b6 101 [$2])])
67a25fed 102m4_pushdef([AT_PURE_AND_LOC_IF],
d9df47b6 103[m4_bmatch([$3], [%locations], [AT_PURE_IF($@)], [$2])])
67a25fed
AD
104m4_pushdef([AT_GLR_OR_PARAM_IF],
105[m4_bmatch([$3], [%glr-parser\|%parse-param], [$1], [$2])])
aa08666d 106m4_pushdef([AT_NAME_PREFIX],
02975b9a
JD
107[m4_bmatch([$3], [%name-prefix ".*"],
108 [m4_bregexp([$3], [name-prefix "\([^"]*\)"], [\1])],
5cf61e93 109 [yy])])
417e31d2 110m4_pushdef([AT_TOKEN_PREFIX],
4c6622c2
AD
111[m4_bmatch([$3], [%define api.tokens.prefix ".*"],
112 [m4_bregexp([$3], [%define api.tokens.prefix "\(.*\)"], [\1])])])
67a25fed
AD
113# yyerror receives the location if %location & %pure & (%glr or %parse-param).
114m4_pushdef([AT_YYERROR_ARG_LOC_IF],
115[AT_GLR_OR_PARAM_IF([AT_PURE_AND_LOC_IF([$1], [$2])],
02650b7f 116 [$2])])
67a25fed 117# yyerror always sees the locations (when activated), except if
94ebeba5 118# (yacc & pure & !param). FIXME: This is wrong. See the manual.
67a25fed 119m4_pushdef([AT_YYERROR_SEES_LOC_IF],
7d596384
JD
120[AT_LOCATION_IF([AT_YACC_IF([AT_PURE_IF([AT_PARAM_IF([$1], [$2])],
121 [$1])],
122 [$1])],
94ebeba5 123 [$2])])
67a25fed 124
d9df47b6 125# The interface is pure: either because %define api.pure, or because we
67a25fed
AD
126# are using the C++ parsers.
127m4_pushdef([AT_PURE_LEX_IF],
94ebeba5 128[AT_PURE_IF([$1],
aa08666d 129 [AT_SKEL_CC_IF([$1], [$2])])])
67a25fed
AD
130
131AT_PURE_LEX_IF(
ebc3737e
PE
132[m4_pushdef([AT_LOC], [(*llocp)])
133 m4_pushdef([AT_VAL], [(*lvalp)])
67a25fed 134 m4_pushdef([AT_LEX_FORMALS],
02650b7f 135 [YYSTYPE *lvalp[]AT_LOCATION_IF([, YYLTYPE *llocp])])
67a25fed 136 m4_pushdef([AT_LEX_ARGS],
02650b7f 137 [lvalp[]AT_LOCATION_IF([, llocp])])
67a25fed 138 m4_pushdef([AT_USE_LEX_ARGS],
02650b7f 139 [(void) lvalp;AT_LOCATION_IF([(void) llocp])])
67a25fed 140 m4_pushdef([AT_LEX_PRE_FORMALS],
02650b7f 141 [AT_LEX_FORMALS, ])
67a25fed 142 m4_pushdef([AT_LEX_PRE_ARGS],
02650b7f 143 [AT_LEX_ARGS, ])
67a25fed 144],
6c88b51e
JD
145[m4_pushdef([AT_LOC], [[(]AT_NAME_PREFIX[lloc)]])
146 m4_pushdef([AT_VAL], [[(]AT_NAME_PREFIX[lval)]])
67a25fed
AD
147 m4_pushdef([AT_LEX_FORMALS], [void])
148 m4_pushdef([AT_LEX_ARGS], [])
149 m4_pushdef([AT_USE_LEX_ARGS], [])
150 m4_pushdef([AT_LEX_PRE_FORMALS], [])
151 m4_pushdef([AT_LEX_PRE_ARGS], [])
152])
4f756f88
AD
153
154# Handle the different types of location components.
155
156AT_SKEL_CC_IF(
157 [AT_LOCATION_TYPE_IF(
49976d5c 158 [AT_LOC_PUSHDEF([first.l], [first.c], [last.l], [last.c])],
4f756f88
AD
159 [AT_LOC_PUSHDEF([begin.line], [begin.column], [end.line], [end.column])])],
160 [AT_LOC_PUSHDEF([first_line], [first_column], [last_line], [last_column])])
161
162
6130b755 163AT_GLR_IF([AT_KEYWORDS([glr])])
67a25fed
AD
164])# _AT_BISON_OPTION_PUSHDEFS
165
166
167# AT_BISON_OPTION_POPDEFS
168# -----------------------
169m4_define([AT_BISON_OPTION_POPDEFS],
170[m4_popdef([AT_LEX_PRE_ARGS])
171m4_popdef([AT_LEX_PRE_FORMALS])
172m4_popdef([AT_USE_LEX_ARGS])
173m4_popdef([AT_LEX_ARGS])
174m4_popdef([AT_LEX_FORMALS])
175m4_popdef([AT_VAL])
176m4_popdef([AT_LOC])
177m4_popdef([AT_PURE_LEX_IF])
178m4_popdef([AT_YYERROR_SEES_LOC_IF])
179m4_popdef([AT_YYERROR_ARG_LOC_IF])
aa08666d 180m4_popdef([AT_NAME_PREFIX])
67a25fed
AD
181m4_popdef([AT_GLR_OR_PARAM_IF])
182m4_popdef([AT_PURE_AND_LOC_IF])
24bb8c8c 183m4_popdef([AT_LOCATION_TYPE_IF])
67a25fed
AD
184m4_popdef([AT_LOCATION_IF])
185m4_popdef([AT_PARAM_IF])
01b477c6 186m4_popdef([AT_LEXPARAM_IF])
67a25fed
AD
187m4_popdef([AT_YACC_IF])
188m4_popdef([AT_GLR_IF])
8f7e3cf9
AD
189m4_popdef([AT_SKEL_CC_IF])
190m4_popdef([AT_GLR_CC_IF])
67a25fed 191m4_popdef([AT_LALR1_CC_IF])
6c88b51e 192m4_popdef([AT_DEFINES_IF])
4f756f88 193AT_LOC_POPDEF
67a25fed
AD
194])# AT_BISON_OPTION_POPDEFS
195
196
197
198## -------------------------- ##
199## Generating Grammar Files. ##
200## -------------------------- ##
201
6c88b51e 202# AT_DATA_SOURCE_PROLOGUE
67a25fed 203# ------------------------
6c88b51e 204# The prologue that should be included in any source code that is
67a25fed 205# meant to be compiled.
6c88b51e
JD
206m4_define([AT_DATA_SOURCE_PROLOGUE],
207[[#include <config.h>
231ed89a
PE
208/* We don't need perfect functions for these tests. */
209#undef malloc
210#undef memcmp
211#undef realloc
6c88b51e
JD
212]])
213
214# AT_DATA_GRAMMAR_PROLOGUE
215# ------------------------
216# The prologue that should be included in any grammar which parser is
217# meant to be compiled.
218m4_define([AT_DATA_GRAMMAR_PROLOGUE],
219[[%code top {
220]AT_DATA_SOURCE_PROLOGUE[]dnl
221[}
222]])
67a25fed 223
6c88b51e
JD
224# AT_DATA_SOURCE(NAME, CONTENT)
225# -----------------------------
226# Generate the file NAME, which CONTENT is preceded by
227# AT_DATA_SOURCE_PROLOGUE.
228m4_define([AT_DATA_SOURCE],
229[AT_DATA([$1],
230[AT_DATA_SOURCE_PROLOGUE
231$2])
232])
67a25fed
AD
233
234# AT_DATA_GRAMMAR(NAME, CONTENT)
235# ------------------------------
236# Generate the file NAME, which CONTENT is preceded by
237# AT_DATA_GRAMMAR_PROLOGUE.
238m4_define([AT_DATA_GRAMMAR],
239[AT_DATA([$1],
240[AT_DATA_GRAMMAR_PROLOGUE
241$2])
242])
243
da730230
JD
244# AT_BISON_CHECK(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
245# -------------------------------------------------
246# Check Bison by invoking `bison BISON_ARGS'. OTHER_AT_CHECK_ARGS are the
247# usual remaining arguments to AT_CHECK: STATUS, STDOUT, etc.
248#
249# This macro or AT_BISON_CHECK_NO_XML should always be used whenever invoking
250# Bison in the test suite. For now it ensures that:
251#
252# 1. Valgrind doesn't report reachable memory when Bison is expected to have
253# a non-zero exit status since Bison doesn't always try to free all memory
254# in that case.
255#
256# 2. In the case of maintainer-xml-check, XML/XSLT output is compared with
257# --graph and --report=all output for every working grammar.
258m4_define([AT_BISON_CHECK],
259[m4_if(m4_quote($2), [0], [AT_BISON_CHECK_XML($@)],
260 m4_quote($2), [], [AT_BISON_CHECK_XML($@)])
261AT_BISON_CHECK_NO_XML($@)])
262
263# AT_BISON_CHECK_NO_XML(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
264# --------------------------------------------------------
265# Same as AT_BISON_CHECK except don't perform XML/XSLT checks. This is useful
266# when a tortured grammar's XML is known to be too large for xsltproc to
267# handle.
268m4_define([AT_BISON_CHECK_NO_XML],
269[AT_CHECK(m4_if(m4_quote($2), [0], [], m4_quote($2), [], [],
270 [AT_QUELL_VALGRIND ])[[bison ]]$@)])
271
272# AT_BISON_CHECK_XML(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
273# -----------------------------------------------------
274# Run AT_BISON_CHECK's XML/XSLT checks if $BISON_TEST_XML=1 and $XSLTPROC is
275# defined. It doesn't make sense to invoke this macro if Bison is expected to
276# have a non-zero exit status.
277m4_define([AT_BISON_CHECK_XML],
247b8c21
JD
278[[if test x"$BISON_TEST_XML" = x1 && test x"$XSLTPROC" != x""; then
279 mkdir xml-tests]
da730230
JD
280 m4_pushdef([AT_BISON_ARGS],
281 [m4_bpatsubsts([[$1]],
282 [--report(-file)?=[^][ ]*], [],
283 [--graph=[^][ ]*], [],
284 [--xml=[^][ ]*], [])])dnl
285 # Don't combine these Bison invocations since we want to be sure that
286 # --report=all isn't required to get the full XML file.
287 AT_CHECK([[bison --report=all --report-file=xml-tests/test.output \
288 --graph=xml-tests/test.dot ]]AT_BISON_ARGS,
289 [[0]], [ignore], [ignore])
290 AT_CHECK([[bison --xml=xml-tests/test.xml ]]AT_BISON_ARGS,
291 [[0]], [ignore], [ignore])
292 m4_popdef([AT_BISON_ARGS])dnl
247b8c21 293 [cp xml-tests/test.output expout]
da730230
JD
294 AT_CHECK([[$XSLTPROC \
295 `]]AT_QUELL_VALGRIND[[ bison --print-datadir`/xslt/xml2text.xsl \
296 xml-tests/test.xml]], [[0]], [expout])
247b8c21 297 [cp xml-tests/test.dot expout]
da730230
JD
298 AT_CHECK([[$XSLTPROC \
299 `]]AT_QUELL_VALGRIND[[ bison --print-datadir`/xslt/xml2dot.xsl \
300 xml-tests/test.xml]], [[0]], [expout])
247b8c21
JD
301 [rm -rf xml-tests expout
302fi]])
da730230
JD
303
304# AT_QUELL_VALGRIND
305# -----------------
306# Put this before a Bison invocation to keep Valgrind from complaining about
307# reachable memory.
308#
309# Do not quote invocations of this macro within the first argument of AT_CHECK.
310# The triple quoting below will cause test cases to fail if you do. If you do
311# so anyway but also decrease the quoting below to avoid that problem, AT_CHECK
312# will then fail to shell-escape its contents when attempting to print them.
313# The testsuite verbose output, at least, will be incorrect, but nothing may
314# fail to make sure you notice.
315m4_define([AT_QUELL_VALGRIND],
316[[[VALGRIND_OPTS="$VALGRIND_OPTS --leak-check=summary --show-reachable=no"; export VALGRIND_OPTS;]]])
67a25fed
AD
317
318## ------------------------ ##
319## Compiling C, C++ Files. ##
320## ------------------------ ##
321
322
323# AT_COMPILE(OUTPUT, [SOURCES = OUTPUT.c])
324# ----------------------------------------
325# Compile SOURCES into OUTPUT. If OUTPUT does not contain '.',
326# assume that we are linking too; this is a hack.
327m4_define([AT_COMPILE],
72d848c2 328[AT_CHECK([$CC $CFLAGS $CPPFLAGS m4_bmatch([$1], [[.]], [], [$LDFLAGS ])-o $1 m4_default([$2], [$1.c])[]m4_bmatch([$1], [[.]], [], [ $LIBS])],
006d217d 329 0, [ignore], [ignore])])
67a25fed 330
07971983 331# AT_COMPILE_CXX(OUTPUT, [SOURCES = OUTPUT.cc])
67a25fed 332# --------------------------------------------
51f4735e
PE
333# Compile SOURCES into OUTPUT. If OUTPUT does not contain '.',
334# assume that we are linking too; this is a hack.
209ea708 335# If the C++ compiler does not work, ignore the test.
67a25fed
AD
336m4_define([AT_COMPILE_CXX],
337[AT_KEYWORDS(c++)
209ea708 338AT_CHECK([$BISON_CXX_WORKS], 0, ignore, ignore)
e6efa9da 339AT_CHECK([$CXX $CXXFLAGS $CPPFLAGS m4_bmatch([$1], [[.]], [], [$LDFLAGS ])-o $1 m4_default([$2], [$1.cc])[]m4_bmatch([$1], [[.]], [], [ $LIBS])],
02650b7f 340 0, [ignore], [ignore])])
67a25fed
AD
341
342
6c88b51e
JD
343# AT_FULL_COMPILE(OUTPUT, [OTHER])
344# --------------------------------
7ca2266a 345# Compile OUTPUT.y to OUTPUT.c or OUTPUT.cc, and compile it to OUTPUT.
6c88b51e
JD
346# If OTHER is specified, compile OUTPUT-OTHER.c or OUTPUT-OTHER.cc to OUTPUT
347# along with it.
7ca2266a
AD
348# Relies on AT_SKEL_CC_IF.
349m4_define([AT_FULL_COMPILE],
350[AT_SKEL_CC_IF(
351 [AT_BISON_CHECK([-o $1.cc $1.y])
6c88b51e 352 AT_COMPILE_CXX([$1]m4_ifval($2, [, [$1.cc $1-$2.cc]]))],
7ca2266a 353 [AT_BISON_CHECK([-o $1.c $1.y])
6c88b51e 354 AT_COMPILE([$1]m4_ifval($2, [, [$1.c $1-$2.c]]))])
7ca2266a
AD
355])
356
67a25fed
AD
357
358## ---------------------------- ##
359## Running a generated parser. ##
360## ---------------------------- ##
361
e0ac9b4b
JD
362# AT_PARSER_CHECK(COMMAND, EXIT-STATUS, EXPOUT, EXPERR, [PRE])
363# ------------------------------------------------------------
67a25fed
AD
364# So that we can run `./testsuite PREPARSER='valgrind -q' for instance.
365m4_define([AT_PARSER_CHECK],
e0ac9b4b 366[AT_CHECK([$5 $PREPARSER $1], [$2], [$3], [$4])])
1f7a61ff 367
7254f6a8
JD
368# AT_TEST_TABLES_AND_PARSE(TITLE, COND-VALUE, TEST-SPEC,
369# DECLS, GRAMMAR, INPUT,
370# BISON-STDERR, TABLES-OR-LAST-STATE,
371# [OTHER-CHECKS],
372# [PARSER-EXIT-VALUE],
373# [PARSER-STDOUT], [PARSER-STDERR])
374# -------------------------------------------------------------
375# Using TITLE as the test group title, check the generated parser tables
376# and parser for a specified grammar file under a condition labeled by
377# COND-VALUE.
378#
379# TEST-SPEC is a comma-delimited list of attributes of this test. Each
380# recognized attribute is described below where it is relevant.
381#
382# Insert DECLS and GRAMMAR into the declarations and grammar section of
383# the grammar file. Insert basic yyerror, yylex, and main function
384# definitions as well. Hardcode yylex to return the (possibly empty)
385# comma-delimited series of tokens in INPUT followed by token 0.
386#
387# If TEST-SPEC contains the attribute no-xml, then invoke bison using
388# AT_BISON_CHECK_NO_XML. Otherwise, invoke bison using AT_BISON_CHECK.
389# On the bison command-line, specify `--report=all --defines'. Check
390# that Bison exits with value 0, has no stdout, and has stderr
391# BISON-STDERR.
392#
393# If TEST-SPEC contains the attribute `last-state', check that the value
394# of TABLES-OR-LAST-STATE is the index of the last state generated for
395# the grammar; in other words, check the number of states (minus one).
396# Otherwise, check that everything in the `.output' file starting with
397# the definition of state 0 is the same as the entire value of
398# TABLES-OR-LAST-STATE.
399#
400# Expand the M4 in OTHER-CHECKS to perform additional checks of the
401# `.output' file, which is named `input.output', and/or grammar file,
402# which is named `input.y'.
403#
404# Finally, compile the generated parser and then run it using
405# AT_PARSER_CHECK with PARSER-EXIT-VALUE, PARSER-STDOUT, and
406# PARSER-STDERR as the 2nd-4th arguments.
407#
408# As a precondition, you must properly double-quote all arguments that
409# are to be interpreted as strings.
410#
411# AT_COND_CASE (when appearing in single-quoted segments of arguments)
412# invokes m4_case with its own arguments but COND-VALUE inserted as the
413# first argument. This is useful, for example, when wrapping multiple
414# AT_TEST_TABLES_AND_PARSE invocations, each representing a different
415# condition, in another macro.
416#
417# For example:
418#
419# # AT_TEST_SYNTAX_ERROR(DESCRIPTION, DECLS, GRAMMAR, INPUT, LAST-STATE,
420# # PARSER-EXIT-VALUE, PARSER-STDOUT, PARSER-STDERR)
421# # ---------------------------------------------------------------------
422# m4_define([AT_TEST_SYNTAX_ERROR],
423# [
424# AT_TEST_TABLES_AND_PARSE([$1[ with %error-verbose]], [[verbose]],
425# [[last-state]],
426# [[%error-verbose ]$2], [$3], [$4],
427# [[]], [$5], [], [$6], [$7], [$8])
428# AT_TEST_TABLES_AND_PARSE([$1[ with no %error-verbose]], [[no verbose]],
429# [[last-state]],
430# [$2], [$3], [$4],
431# [[]], [$5], [], [$6], [$7], [$8])
432# ])
433#
434# AT_TEST_SYNTAX_ERROR([[Single Char Grammar]],
435# [[%token 'b']], [[start: 'a' ;]], [['a', 'b']],
436# [[3]],
437# [[1]], [[]],
438# [AT_COND_CASE([[no verbose]],
439# [[syntax error
440# ]],
441# [[syntax error, unexpected 'b', expecting $end
442# ]])])
443m4_define([AT_TEST_TABLES_AND_PARSE],
c4be5517 444[m4_pushdef([AT_COND_CASE], [m4_case([$2], $][@)])
7254f6a8 445
c4be5517 446AT_SETUP([$1])
7254f6a8
JD
447
448AT_DATA_GRAMMAR([[input.y]],
449[[%code {
450 #include <stdio.h>
451 static void yyerror (char const *msg);
452 static int yylex (void);
453}
454
c4be5517 455]$4[
7254f6a8
JD
456
457%%
458
c4be5517 459]$5[
7254f6a8
JD
460
461%%
462
463static void
464yyerror (char const *msg)
465{
466 fprintf (stderr, "%s\n", msg);
467}
468
469static int
470yylex (void)
471{
472 static int const input[] = {
c4be5517 473 ]m4_if([$6], [], [], [$6], [[]], [], [$6[, ]])[0
7254f6a8
JD
474 };
475 static int const *inputp = input;
476 return *inputp++;
477}
478
479int
480main (void)
481{
482 return yyparse ();
483}
484]])
485
c4be5517
JD
486# In some versions of Autoconf, AT_CHECK invokes AS_ESCAPE before
487# expanding macros, so it corrupts some special characters in the
488# macros. To avoid this, expand now and pass it the result with proper
489# string quotation. Assume args 7 thru 12 expand to properly quoted
490# strings.
7254f6a8 491
c4be5517 492m4_if(m4_index(m4_quote($3), [no-xml]), -1,
7254f6a8
JD
493 [AT_BISON_CHECK],
494 [AT_BISON_CHECK_NO_XML])([[--report=all --defines -o input.c input.y]],
c4be5517 495 [0], [], m4_dquote($7))
7254f6a8 496
c4be5517 497m4_if(m4_index(m4_quote($3), [last-state]), -1,
7254f6a8 498 [AT_CHECK([[sed -n '/^state 0$/,$p' input.output]], [[0]],
c4be5517 499 m4_dquote($8))],
7254f6a8 500 [AT_CHECK([[sed -n 's/^state //p' input.output | tail -1]], [[0]],
c4be5517 501 m4_dquote($8)[[
7254f6a8 502]])])
7254f6a8 503
c4be5517 504$9
7254f6a8
JD
505
506AT_COMPILE([[input]])
507
c4be5517
JD
508AT_PARSER_CHECK([[./input]],
509 m4_ifval([$10], [m4_dquote($10)]),
510 m4_ifval([$11], [m4_dquote($11)]),
511 m4_ifval([$12], [m4_dquote($12)]))
7254f6a8
JD
512
513AT_CLEANUP
514
515m4_popdef([AT_COND_CASE])])
1f7a61ff
AD
516
517
518
519## ----------------------- ##
520## Launch the test suite. ##
521## ----------------------- ##
522
523AT_INIT
524
525AT_TESTED([bison])