]> git.saurik.com Git - bison.git/blame - tests/local.at
comment changes
[bison.git] / tests / local.at
CommitLineData
67a25fed
AD
1# Process this -*- Autotest -*- file with autom4te.
2
3# Macros for the GNU Bison Test suite.
6e30ede8 4
c932d613 5# Copyright (C) 2003-2012 Free Software Foundation, Inc.
67a25fed 6
f16b0819 7# This program is free software: you can redistribute it and/or modify
67a25fed 8# it under the terms of the GNU General Public License as published by
f16b0819
PE
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
67a25fed
AD
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
f16b0819 16#
67a25fed 17# You should have received a copy of the GNU General Public License
f16b0819 18# along with this program. If not, see <http://www.gnu.org/licenses/>.
67a25fed 19
ce05140d 20m4_version_prereq([2.58])
1f7a61ff 21
67a25fed 22
a122efad
AD
23# m4_null_if(VAL, IF-TRUE, IF-FALSE)
24# ----------------------------------
25# If VAL evaluates to empty or 0, run IF-TRUE, otherwise IF-FALSE.
26m4_define([m4_null_if],
27[m4_case(m4_quote($1),
28 [0], [$2],
29 [], [$2],
30 [$3])])
31
c4fae1ef
AD
32## ------------- ##
33## Basic tests. ##
34## ------------- ##
35
36# AT_MATCHES_CHECK(FILE, PERL-REGEXP, COUNT)
37# ------------------------------------------
38# Expect COUNT matches of the PERL-REGEXP in FILE. The file is
39# taken in "slurp" mode, i.e., one can match end-of-lines.
40m4_define([AT_MATCHES_CHECK],
c955769a 41[AT_CHECK([$PERL -0777 -ne '
c4fae1ef
AD
42my $count = 0;
43s{$2}{ ++$count; "" }gem;
44printf "$count\n";' $1], [0], [$3
45])])
46
47
5192fd5d
AD
48# AT_SAVE_SPECIAL_FILES / AT_RESTORE_SPECIAL_FILES
49# ------------------------------------------------
50# Don't interfere with caller's files.
51m4_divert_text([PREPARE_TESTS],
52[at_save_special_files ()
53{
54 for at_save_file in stderr experr expout
55 do
1aa9fa82
AD
56 test ! -f at-bison-check-$at_save_file.bak ||
57 as_fn_error 1 "fatal error: back-up on top of a back-up"
5192fd5d
AD
58 test ! -f $at_save_file || mv $at_save_file at-bison-check-$at_save_file.bak
59 done
60}
61
62at_restore_special_files ()
63{
64 for at_save_file in stderr experr expout
65 do
66 test ! -f at-bison-check-$at_save_file.bak ||
67 mv at-bison-check-$at_save_file.bak $at_save_file
68 done
69}
70])
71
72m4_define([AT_SAVE_SPECIAL_FILES], [at_save_special_files])
73m4_define([AT_RESTORE_SPECIAL_FILES], [at_restore_special_files])
74
75
76
67a25fed
AD
77## ------------------------------- ##
78## Macros decoding Bison options. ##
79## ------------------------------- ##
80
ed228e60
AD
81# AT_LOC_PUSHDEF(FIRST-LINE, FIRST-COLUMN, LAST-LINE, LAST-COLUMN)
82# ----------------------------------------------------------------
83# Pushdef AT_LOC_(FIRST|LAST)_(LINE|COLUMN).
84m4_define([AT_LOC_PUSHDEF],
85[m4_pushdef([AT_LOC_FIRST_LINE], [AT_LOC.$1])
86m4_pushdef([AT_LOC_FIRST_COLUMN], [AT_LOC.$2])
87m4_pushdef([AT_LOC_LAST_LINE], [AT_LOC.$3])
88m4_pushdef([AT_LOC_LAST_COLUMN], [AT_LOC.$4])])
89
90# AT_LOC_POPDEF
91# -------------
92# Popdef AT_LOC_(FIRST|LAST)_(LINE|COL).
93m4_define([AT_LOC_POPDEF],
94[m4_popdef([AT_LOC_FIRST_LINE])
95m4_popdef([AT_LOC_FIRST_COLUMN])
96m4_popdef([AT_LOC_LAST_LINE])
97m4_popdef([AT_LOC_LAST_COLUMN])])
98
99
67a25fed
AD
100
101# AT_BISON_OPTION_PUSHDEFS([BISON-OPTIONS])
102# -----------------------------------------
103m4_define([AT_BISON_OPTION_PUSHDEFS],
a32a2d57
AD
104[m4_divert_text([KILL],
105 [_AT_BISON_OPTION_PUSHDEFS($[1], $[2], [$1])])])
67a25fed
AD
106
107
108# _AT_BISON_OPTION_PUSHDEFS($1, $2, [BISON-OPTIONS])
109# --------------------------------------------------
110# This macro works around the impossibility to define macros
111# inside macros, because issuing `[$1]' is not possible in M4 :(.
112# This sucks hard, GNU M4 should really provide M5 like $$1.
113m4_define([_AT_BISON_OPTION_PUSHDEFS],
114[m4_if([$1$2], $[1]$[2], [],
115 [m4_fatal([$0: Invalid arguments: $@])])dnl
462503f8
JD
116m4_pushdef([AT_DEFINES_IF],
117[m4_bmatch([$3], [%defines], [$1], [$2])])
8f7e3cf9 118m4_pushdef([AT_SKEL_CC_IF],
0e021770 119[m4_bmatch([$3], [%language "[Cc]\+\+"\|%skeleton "[a-z0-9]+\.cc"], [$1], [$2])])
095a1d11
JD
120m4_pushdef([AT_SKEL_JAVA_IF],
121[m4_bmatch([$3], [%language "[Jj][Aa][Vv][Aa]"\|%skeleton "[a-z0-9]+\.java"], [$1], [$2])])
2d40532b
AD
122m4_pushdef([AT_LANG],
123[AT_SKEL_JAVA_IF([java],
05a7b6ec 124 [AT_SKEL_CC_IF([c++],
2d40532b 125 [c])])])
67a25fed 126m4_pushdef([AT_GLR_IF],
5f7f1e21 127[m4_bmatch([$3], [%glr-parser\|%skeleton "glr\..*"], [$1], [$2])])
0e021770
PE
128m4_pushdef([AT_LALR1_CC_IF],
129[AT_SKEL_CC_IF([AT_GLR_IF([$2], [$1])], [$2])])
130m4_pushdef([AT_GLR_CC_IF],
131[AT_SKEL_CC_IF([AT_GLR_IF([$1], [$2])], [$2])])
67a25fed
AD
132# Using yacc.c?
133m4_pushdef([AT_YACC_IF],
0e021770 134[m4_bmatch([$3], [%language\|%glr-parser\|%skeleton], [$2], [$1])])
01b477c6
PB
135m4_pushdef([AT_LEXPARAM_IF],
136[m4_bmatch([$3], [%lex-param], [$1], [$2])])
67a25fed
AD
137m4_pushdef([AT_LOCATION_IF],
138[m4_bmatch([$3], [%locations], [$1], [$2])])
cacfdef7
AD
139m4_pushdef([AT_LOCATION_TYPE_IF],
140[m4_bmatch([$3], [%define location_type], [$1], [$2])])
141m4_pushdef([AT_PARAM_IF],
142[m4_bmatch([$3], [%parse-param], [$1], [$2])])
67a25fed 143m4_pushdef([AT_PURE_IF],
d9df47b6 144[m4_bmatch([$3], [%define *api\.pure\|%pure-parser],
f37495f6 145 [m4_bmatch([$3], [%define *api\.pure *"?false"?], [$2], [$1])],
d9df47b6 146 [$2])])
67a25fed 147m4_pushdef([AT_PURE_AND_LOC_IF],
d9df47b6 148[m4_bmatch([$3], [%locations], [AT_PURE_IF($@)], [$2])])
67a25fed
AD
149m4_pushdef([AT_GLR_OR_PARAM_IF],
150[m4_bmatch([$3], [%glr-parser\|%parse-param], [$1], [$2])])
aa08666d 151m4_pushdef([AT_NAME_PREFIX],
230a3db4
AD
152[m4_bmatch([$3], [\(%define api\.prefix\|%name-prefix\) ".*"],
153 [m4_bregexp([$3], [\(%define api\.prefix\|%name-prefix\) "\([^""]*\)"], [\2])],
71c7e24f 154 [yy])])
837b7696
AD
155m4_pushdef([AT_API_prefix],
156[m4_bmatch([$3], [%define api\.prefix ".*"],
157 [m4_bregexp([$3], [%define api\.prefix "\([^""]*\)"], [\1])],
158 [yy])])
4b3847c3
AD
159m4_pushdef([AT_API_PREFIX],
160[m4_toupper(AT_API_prefix)])
67a25fed
AD
161# yyerror receives the location if %location & %pure & (%glr or %parse-param).
162m4_pushdef([AT_YYERROR_ARG_LOC_IF],
163[AT_GLR_OR_PARAM_IF([AT_PURE_AND_LOC_IF([$1], [$2])],
02650b7f 164 [$2])])
67a25fed 165# yyerror always sees the locations (when activated), except if
94ebeba5 166# (yacc & pure & !param). FIXME: This is wrong. See the manual.
67a25fed 167m4_pushdef([AT_YYERROR_SEES_LOC_IF],
7d596384
JD
168[AT_LOCATION_IF([AT_YACC_IF([AT_PURE_IF([AT_PARAM_IF([$1], [$2])],
169 [$1])],
170 [$1])],
94ebeba5 171 [$2])])
67a25fed 172
d9df47b6 173# The interface is pure: either because %define api.pure, or because we
67a25fed
AD
174# are using the C++ parsers.
175m4_pushdef([AT_PURE_LEX_IF],
94ebeba5 176[AT_PURE_IF([$1],
aa08666d 177 [AT_SKEL_CC_IF([$1], [$2])])])
67a25fed 178
0e16927b
AD
179m4_pushdef([AT_YYSTYPE],
180[AT_SKEL_CC_IF([AT_NAME_PREFIX[::parser::semantic_type]],
4b3847c3 181 [AT_API_PREFIX[STYPE]])])
0e16927b
AD
182m4_pushdef([AT_YYLTYPE],
183[AT_SKEL_CC_IF([AT_NAME_PREFIX[::parser::location_type]],
4b3847c3 184 [AT_API_PREFIX[LTYPE]])])
0e16927b
AD
185
186
67a25fed 187AT_PURE_LEX_IF(
ebc3737e
PE
188[m4_pushdef([AT_LOC], [(*llocp)])
189 m4_pushdef([AT_VAL], [(*lvalp)])
230a3db4 190 m4_pushdef([AT_YYLEX_FORMALS],
0e16927b 191 [AT_YYSTYPE *lvalp[]AT_LOCATION_IF([, AT_YYLTYPE *llocp])])
230a3db4 192 m4_pushdef([AT_YYLEX_ARGS],
02650b7f 193 [lvalp[]AT_LOCATION_IF([, llocp])])
67a25fed 194 m4_pushdef([AT_USE_LEX_ARGS],
02650b7f 195 [(void) lvalp;AT_LOCATION_IF([(void) llocp])])
230a3db4
AD
196 m4_pushdef([AT_YYLEX_PRE_FORMALS],
197 [AT_YYLEX_FORMALS, ])
198 m4_pushdef([AT_YYLEX_PRE_ARGS],
199 [AT_YYLEX_ARGS, ])
67a25fed 200],
462503f8
JD
201[m4_pushdef([AT_LOC], [[(]AT_NAME_PREFIX[lloc)]])
202 m4_pushdef([AT_VAL], [[(]AT_NAME_PREFIX[lval)]])
230a3db4
AD
203 m4_pushdef([AT_YYLEX_FORMALS], [void])
204 m4_pushdef([AT_YYLEX_ARGS], [])
67a25fed 205 m4_pushdef([AT_USE_LEX_ARGS], [])
230a3db4
AD
206 m4_pushdef([AT_YYLEX_PRE_FORMALS], [])
207 m4_pushdef([AT_YYLEX_PRE_ARGS], [])
67a25fed 208])
ed228e60
AD
209
210# Handle the different types of location components.
211
212AT_SKEL_CC_IF(
213 [AT_LOCATION_TYPE_IF(
0f404a0a 214 [AT_LOC_PUSHDEF([first.l], [first.c], [last.l], [last.c])],
ed228e60
AD
215 [AT_LOC_PUSHDEF([begin.line], [begin.column], [end.line], [end.column])])],
216 [AT_LOC_PUSHDEF([first_line], [first_column], [last_line], [last_column])])
217
67a25fed
AD
218])# _AT_BISON_OPTION_PUSHDEFS
219
220
221# AT_BISON_OPTION_POPDEFS
222# -----------------------
223m4_define([AT_BISON_OPTION_POPDEFS],
a32a2d57 224[m4_divert_text([KILL],
230a3db4
AD
225[m4_popdef([AT_YYLEX_PRE_ARGS])
226m4_popdef([AT_YYLEX_PRE_FORMALS])
67a25fed 227m4_popdef([AT_USE_LEX_ARGS])
230a3db4
AD
228m4_popdef([AT_YYLEX_ARGS])
229m4_popdef([AT_YYLEX_FORMALS])
0e16927b
AD
230m4_popdef([AT_YYLTYPE])
231m4_popdef([AT_YYSTYPE])
67a25fed
AD
232m4_popdef([AT_VAL])
233m4_popdef([AT_LOC])
234m4_popdef([AT_PURE_LEX_IF])
235m4_popdef([AT_YYERROR_SEES_LOC_IF])
236m4_popdef([AT_YYERROR_ARG_LOC_IF])
4b3847c3 237m4_popdef([AT_API_PREFIX])
837b7696 238m4_popdef([AT_API_prefix])
aa08666d 239m4_popdef([AT_NAME_PREFIX])
67a25fed
AD
240m4_popdef([AT_GLR_OR_PARAM_IF])
241m4_popdef([AT_PURE_AND_LOC_IF])
cacfdef7 242m4_popdef([AT_LOCATION_TYPE_IF])
67a25fed
AD
243m4_popdef([AT_LOCATION_IF])
244m4_popdef([AT_PARAM_IF])
01b477c6 245m4_popdef([AT_LEXPARAM_IF])
67a25fed
AD
246m4_popdef([AT_YACC_IF])
247m4_popdef([AT_GLR_IF])
8f7e3cf9 248m4_popdef([AT_SKEL_CC_IF])
2d40532b 249m4_popdef([AT_LANG])
095a1d11 250m4_popdef([AT_SKEL_JAVA_IF])
8f7e3cf9 251m4_popdef([AT_GLR_CC_IF])
67a25fed 252m4_popdef([AT_LALR1_CC_IF])
462503f8 253m4_popdef([AT_DEFINES_IF])
a32a2d57 254AT_LOC_POPDEF])dnl
67a25fed
AD
255])# AT_BISON_OPTION_POPDEFS
256
257
258
259## -------------------------- ##
260## Generating Grammar Files. ##
261## -------------------------- ##
262
462503f8 263# AT_DATA_SOURCE_PROLOGUE
67a25fed 264# ------------------------
462503f8 265# The prologue that should be included in any source code that is
67a25fed 266# meant to be compiled.
462503f8
JD
267m4_define([AT_DATA_SOURCE_PROLOGUE],
268[[#include <config.h>
231ed89a
PE
269/* We don't need perfect functions for these tests. */
270#undef malloc
271#undef memcmp
272#undef realloc
462503f8 273]])
67a25fed 274
462503f8
JD
275# AT_DATA_GRAMMAR_PROLOGUE
276# ------------------------
277# The prologue that should be included in any grammar which parser is
278# meant to be compiled.
279m4_define([AT_DATA_GRAMMAR_PROLOGUE],
280[[%code top {
281]AT_DATA_SOURCE_PROLOGUE[]dnl
282[}
283]])
284
285# AT_DATA_SOURCE(NAME, CONTENT)
286# -----------------------------
287# Generate the file NAME, which CONTENT is preceded by
288# AT_DATA_SOURCE_PROLOGUE.
289m4_define([AT_DATA_SOURCE],
290[AT_DATA([$1],
291[AT_DATA_SOURCE_PROLOGUE
292$2])
293])
67a25fed
AD
294
295# AT_DATA_GRAMMAR(NAME, CONTENT)
296# ------------------------------
297# Generate the file NAME, which CONTENT is preceded by
298# AT_DATA_GRAMMAR_PROLOGUE.
299m4_define([AT_DATA_GRAMMAR],
300[AT_DATA([$1],
301[AT_DATA_GRAMMAR_PROLOGUE
302$2])
303])
304
230a3db4 305# AT_YYLEX_PROTOTYPE
55f48c48
AD
306# AT_YYLEX_DECLARE_EXTERN
307# AT_YYLEX_DECLARE
95361618
AD
308# AT_YYLEX_DEFINE([INPUT], [ACTION])
309# ----------------------------------
310# INPUT can be empty, or in double quotes, or a list (in braces).
311# ACTION may compute yylval for instance, using "res" as token type,
312# and "toknum" as the number of calls to yylex (starting at 0).
230a3db4 313m4_define([AT_YYLEX_PROTOTYPE],
837b7696 314[int AT_NAME_PREFIX[]lex (]AT_YYLEX_FORMALS[)[]dnl
230a3db4
AD
315])
316
55f48c48 317m4_define([AT_YYLEX_DECLARE_EXTERN],
230a3db4 318[AT_YYLEX_PROTOTYPE;dnl
55f48c48
AD
319])
320
321m4_define([AT_YYLEX_DECLARE],
322[static AT_YYLEX_DECLARE_EXTERN[]dnl
323])
324
325m4_define([AT_YYLEX_DEFINE],
77519a7d 326[[#include <assert.h>
230a3db4
AD
327static
328]AT_YYLEX_PROTOTYPE[
55f48c48 329{
95361618
AD
330 ]m4_bmatch([$1], [^\(".*"\)?$],
331 [[static char const input[] = ]m4_default([$1], [""])],
332 [[static int const input[] = ]$1])[;
55f48c48
AD
333 static size_t toknum = 0;
334 int res;
0e16927b 335 ]AT_USE_LEX_ARGS[;
55e075f2 336 assert (toknum < sizeof input / sizeof input[0]);
55f48c48 337 res = input[toknum++];
0e16927b
AD
338 ]$2[;]AT_LOCATION_IF([[
339 ]AT_LOC_FIRST_LINE[ = ]AT_LOC_LAST_LINE[ = 1;
340 ]AT_LOC_FIRST_COLUMN[ = ]AT_LOC_LAST_COLUMN[ = toknum;]])[
55f48c48
AD
341 return res;
342}]dnl
343])
344
6d559547 345# AT_YYERROR_PROTOTYPE
55f48c48
AD
346# AT_YYERROR_DECLARE_EXTERN
347# AT_YYERROR_DECLARE
348# AT_YYERROR_DEFINE
349# -------------------------
6d559547 350# Must be called inside a AT_BISON_OPTION_PUSHDEFS/POPDEFS pair.
230a3db4
AD
351m4_define([AT_YYERROR_FORMALS],
352[m4_case(AT_LANG,
ad60e80f 353[c], [AT_YYERROR_ARG_LOC_IF([AT_YYLTYPE *llocp, ])[const char *msg]])[]dnl
230a3db4
AD
354])
355
6d559547
AD
356m4_define([AT_YYERROR_PROTOTYPE],
357[m4_case(AT_LANG,
837b7696 358[c], [[void ]AT_NAME_PREFIX[error (]AT_YYERROR_FORMALS[)]])[]dnl
6d559547
AD
359])
360
55f48c48 361m4_define([AT_YYERROR_DECLARE_EXTERN],
05a7b6ec 362[m4_case(AT_LANG,
6d559547 363[c], [AT_YYERROR_PROTOTYPE;])[]dnl
55f48c48
AD
364])
365
366m4_define([AT_YYERROR_DECLARE],
05a7b6ec
AD
367[m4_case(AT_LANG,
368[c], [static AT_YYERROR_DECLARE_EXTERN])[]dnl
55f48c48
AD
369])
370
371m4_define([AT_YYERROR_DEFINE],
05a7b6ec
AD
372[m4_case(AT_LANG,
373[c], [[#include <stdio.h>
74909941 374/* A C error reporting function. */
6d559547
AD
375static
376]AT_YYERROR_PROTOTYPE[
55f48c48 377{
74909941
AD
378]AT_YYERROR_SEES_LOC_IF([[
379 fprintf (stderr, "%d.%d",
380 ]AT_LOC_FIRST_LINE[, ]AT_LOC_FIRST_COLUMN[);
381 if (]AT_LOC_FIRST_LINE[ != ]AT_LOC_LAST_LINE[)
382 fprintf (stderr, "-%d.%d",
383 ]AT_LOC_LAST_LINE[, ]AT_LOC_LAST_COLUMN[ - 1);
384 else if (]AT_LOC_FIRST_COLUMN[ != ]AT_LOC_LAST_COLUMN[ - 1)
385 fprintf (stderr, "-%d",
386 ]AT_LOC_LAST_COLUMN[ - 1);
387 fprintf (stderr, ": ");]])[
55f48c48 388 fprintf (stderr, "%s\n", msg);
05a7b6ec 389}]],
74909941
AD
390[c++], [[/* A C++ error reporting function. */
391void
392]AT_NAME_PREFIX[::parser::error (const location_type& l, const std::string& m)
05a7b6ec 393{
74909941
AD
394 (void) l;
395 std::cerr << ]AT_LOCATION_IF([l << ": " << ])[m << std::endl;
05a7b6ec 396}]],
6d559547
AD
397[java], [AT_LOCATION_IF([[public void yyerror (Calc.Location l, String s)
398 {
399 if (l == null)
400 System.err.println (s);
401 else
402 System.err.println (l + ": " + s);
403 }
404]], [[
405 public void yyerror (String s)
406 {
407 System.err.println (s);
5b34bb31
AD
408 }]])],
409[m4_fatal([$0: invalid language: ]AT_LANG)])dnl
6d559547 410])
05a7b6ec 411
55f48c48
AD
412
413## --------------- ##
414## Running Bison. ##
415## --------------- ##
416
da730230
JD
417# AT_BISON_CHECK(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
418# -------------------------------------------------
a122efad
AD
419# High-level routine that may call bison several times, under different
420# conditions.
421#
8ffd7912
JD
422# Check Bison by invoking `bison BISON_ARGS'. BISON_ARGS should not contain
423# shell constructs (such as redirection or pipes) that would prevent
424# appending additional command-line arguments for bison. OTHER_AT_CHECK_ARGS
425# are the usual remaining arguments to AT_CHECK: STATUS, STDOUT, etc.
da730230
JD
426#
427# This macro or AT_BISON_CHECK_NO_XML should always be used whenever invoking
428# Bison in the test suite. For now it ensures that:
429#
430# 1. Valgrind doesn't report reachable memory when Bison is expected to have
431# a non-zero exit status since Bison doesn't always try to free all memory
432# in that case.
433#
434# 2. In the case of maintainer-xml-check, XML/XSLT output is compared with
435# --graph and --report=all output for every working grammar.
4631c34f
JD
436#
437# 3. If stderr contains a warning, -Werror and --warnings=error
438# convert the warning to an error.
8ffd7912
JD
439#
440# 4. If stderr contains a warning, -Wnone and --warnings=none suppress it.
da730230 441m4_define([AT_BISON_CHECK],
a122efad 442[m4_null_if([$2], [AT_BISON_CHECK_XML($@)])
da730230
JD
443AT_BISON_CHECK_NO_XML($@)])
444
4631c34f
JD
445m4_define([AT_BISON_WERROR_MSG],
446 [[bison: warnings being treated as errors]])
447
a122efad
AD
448
449# AT_BISON_CHECK_(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
450# --------------------------------------------------
451# Low-level macro to run bison once.
452m4_define([AT_BISON_CHECK_],
453[AT_CHECK(AT_QUELL_VALGRIND[[ bison ]]$@)])
454
455
e4828e23
AD
456# AT_BISON_CHECK_WARNINGS(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
457# ----------------------------------------------------------
458# Check that warnings (if some are expected) are correctly
459# turned into errors with -Werror, etc.
460m4_define([AT_BISON_CHECK_WARNINGS],
461[m4_if(m4_bregexp([$4], [: warning: ]), [-1], [],
462 [m4_null_if([$2], [AT_BISON_CHECK_WARNINGS_($@)])])])
463
464m4_define([AT_BISON_CHECK_WARNINGS_],
94843f0a
AD
465[[# Defining POSIXLY_CORRECT causes bison to complain if options are
466# added after the grammar file name, so skip these checks in that
467# case.
468#
469# Don't just check if $POSIXLY_CORRECT is set, as Bash, when launched
470# as /bin/sh, sets the shell variable POSIXLY_CORRECT to y, but not
471# the environment variable.
472if env | grep '^POSIXLY_CORRECT=' >/dev/null; then :; else
e4828e23
AD
473 ]AT_SAVE_SPECIAL_FILES[
474
475 # To avoid expanding it repeatedly, store specified stdout.
476 ]AT_DATA([expout], [$3])[
477
478 # Run with -Werror.
479 ]AT_BISON_CHECK_([$1[ -Werror]], [[1]], [expout], [stderr])[
480
481 # Build expected stderr up to and including the "warnings being
482 # treated as errors" message.
483 ]AT_DATA([[at-bison-check-warnings]], [$4])[
484 at_bison_check_first=`sed -n \
485 '/: warning: /{=;q;}' at-bison-check-warnings`
486 : ${at_bison_check_first:=1}
487 at_bison_check_first_tmp=`sed -n \
488 '/conflicts: [0-9].*reduce$/{=;q;}' at-bison-check-warnings`
489 : ${at_bison_check_first_tmp:=1}
490 if test $at_bison_check_first_tmp -lt $at_bison_check_first; then
491 at_bison_check_first=$at_bison_check_first_tmp
492 fi
493 if test $at_bison_check_first -gt 1; then
494 sed -n "1,`expr $at_bison_check_first - 1`"p \
495 at-bison-check-warnings > experr
496 fi
497 echo ']AT_BISON_WERROR_MSG[' >> experr
498
499 # Finish building expected stderr and check. Unlike warnings,
500 # complaints cause bison to exit early. Thus, with -Werror, bison
501 # does not necessarily report all warnings that it does without
502 # -Werror, but it at least reports one.
503 at_bison_check_last=`sed -n '$=' stderr`
504 : ${at_bison_check_last:=1}
505 at_bison_check_last=`expr $at_bison_check_last - 1`
506 sed -n "$at_bison_check_first,$at_bison_check_last"p \
507 at-bison-check-warnings >> experr
508 ]AT_CHECK([[sed 's,.*/\(]AT_BISON_WERROR_MSG[\)$,\1,' \
509 stderr 1>&2]], [[0]], [[]], [experr])[
510
511 # Now check --warnings=error.
512 cp stderr experr
513 ]AT_BISON_CHECK_([$1[ --warnings=error]], [[1]], [expout], [experr])[
514
515 # Now check -Wnone and --warnings=none by making sure that
516 # -Werror doesn't change the exit status when -Wnone or
517 # --warnings=none is specified.
518 ]AT_BISON_CHECK_([$1[ -Wnone -Werror]], [[0]], [expout])[
519 ]AT_BISON_CHECK_([$1[ --warnings=none -Werror]], [[0]], [expout])[
520
521 ]AT_RESTORE_SPECIAL_FILES[
522fi]dnl
523])
524
da730230
JD
525# AT_BISON_CHECK_NO_XML(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
526# --------------------------------------------------------
527# Same as AT_BISON_CHECK except don't perform XML/XSLT checks. This is useful
528# when a tortured grammar's XML is known to be too large for xsltproc to
529# handle.
530m4_define([AT_BISON_CHECK_NO_XML],
e4828e23
AD
531[AT_CHECK(m4_null_if([$2], [], [AT_QUELL_VALGRIND ])[[bison ]]$@)
532AT_BISON_CHECK_WARNINGS($@)])
da730230
JD
533
534# AT_BISON_CHECK_XML(BISON_ARGS, [OTHER_AT_CHECK_ARGS])
535# -----------------------------------------------------
536# Run AT_BISON_CHECK's XML/XSLT checks if $BISON_TEST_XML=1 and $XSLTPROC is
537# defined. It doesn't make sense to invoke this macro if Bison is expected to
538# have a non-zero exit status.
539m4_define([AT_BISON_CHECK_XML],
035810ed
AD
540[[if test x"$BISON_TEST_XML" = x1 && test x"$XSLTPROC" != x""; then]
541 AT_SAVE_SPECIAL_FILES
542 [mkdir xml-tests]
da730230
JD
543 m4_pushdef([AT_BISON_ARGS],
544 [m4_bpatsubsts([[$1]],
545 [--report(-file)?=[^][ ]*], [],
546 [--graph=[^][ ]*], [],
547 [--xml=[^][ ]*], [])])dnl
548 # Don't combine these Bison invocations since we want to be sure that
549 # --report=all isn't required to get the full XML file.
a122efad
AD
550 AT_BISON_CHECK_([[--report=all --report-file=xml-tests/test.output \
551 --graph=xml-tests/test.dot ]]AT_BISON_ARGS,
552 [[0]], [ignore], [ignore])
553 AT_BISON_CHECK_([[--xml=xml-tests/test.xml ]]AT_BISON_ARGS,
554 [[0]], [ignore], [ignore])
da730230 555 m4_popdef([AT_BISON_ARGS])dnl
247b8c21 556 [cp xml-tests/test.output expout]
da730230
JD
557 AT_CHECK([[$XSLTPROC \
558 `]]AT_QUELL_VALGRIND[[ bison --print-datadir`/xslt/xml2text.xsl \
559 xml-tests/test.xml]], [[0]], [expout])
247b8c21 560 [cp xml-tests/test.dot expout]
da730230
JD
561 AT_CHECK([[$XSLTPROC \
562 `]]AT_QUELL_VALGRIND[[ bison --print-datadir`/xslt/xml2dot.xsl \
563 xml-tests/test.xml]], [[0]], [expout])
035810ed
AD
564 [rm -rf xml-tests expout]
565 AT_RESTORE_SPECIAL_FILES
566[fi]])
da730230
JD
567
568# AT_QUELL_VALGRIND
569# -----------------
570# Put this before a Bison invocation to keep Valgrind from complaining about
571# reachable memory.
572#
573# Do not quote invocations of this macro within the first argument of AT_CHECK.
574# The triple quoting below will cause test cases to fail if you do. If you do
575# so anyway but also decrease the quoting below to avoid that problem, AT_CHECK
576# will then fail to shell-escape its contents when attempting to print them.
577# The testsuite verbose output, at least, will be incorrect, but nothing may
578# fail to make sure you notice.
579m4_define([AT_QUELL_VALGRIND],
580[[[VALGRIND_OPTS="$VALGRIND_OPTS --leak-check=summary --show-reachable=no"; export VALGRIND_OPTS;]]])
67a25fed 581
e4828e23
AD
582
583
67a25fed
AD
584## ------------------------ ##
585## Compiling C, C++ Files. ##
586## ------------------------ ##
587
588
589# AT_COMPILE(OUTPUT, [SOURCES = OUTPUT.c])
590# ----------------------------------------
91ce0b3a
AD
591# Compile SOURCES into OUTPUT.
592#
593# If OUTPUT does not contain '.', assume that we are linking too,
594# otherwise pass "-c"; this is a hack. The default SOURCES is OUTPUT
595# with trailing .o removed, and ".c" appended.
67a25fed 596m4_define([AT_COMPILE],
91ce0b3a
AD
597[AT_CHECK(m4_join([ ],
598 [$CC $CFLAGS $CPPFLAGS],
599 [m4_bmatch([$1], [[.]], [-c], [$LDFLAGS])],
600 [-o $1],
601 [m4_default([$2], [m4_bpatsubst([$1], [\.o$]).c])],
602 [m4_bmatch([$1], [[.]], [], [$LIBS])]),
006d217d 603 0, [ignore], [ignore])])
67a25fed 604
07971983 605# AT_COMPILE_CXX(OUTPUT, [SOURCES = OUTPUT.cc])
91ce0b3a
AD
606# ---------------------------------------------
607# Compile SOURCES into OUTPUT. If the C++ compiler does not work,
608# ignore the test.
609#
610# If OUTPUT does not contain '.', assume that we are linking too,
611# otherwise pass "-c"; this is a hack. The default SOURCES is OUTPUT
612# with trailing .o removed, and ".cc" appended.
67a25fed
AD
613m4_define([AT_COMPILE_CXX],
614[AT_KEYWORDS(c++)
209ea708 615AT_CHECK([$BISON_CXX_WORKS], 0, ignore, ignore)
91ce0b3a
AD
616AT_CHECK(m4_join([ ],
617 [$CXX $CXXFLAGS $CPPFLAGS],
618 [m4_bmatch([$1], [[.]], [-c], [$LDFLAGS])],
619 [-o $1],
620 [m4_default([$2], [m4_bpatsubst([$1], [\.o$]).cc])],
621 [m4_bmatch([$1], [[.]], [], [$LIBS])]),
02650b7f 622 0, [ignore], [ignore])])
67a25fed 623
095a1d11
JD
624# AT_JAVA_COMPILE(SOURCES)
625# ------------------------
626# Compile SOURCES into Java class files. Skip the test if java or javac
627# is not installed.
628m4_define([AT_JAVA_COMPILE],
629[AT_KEYWORDS(java)
916f26b6
AD
630AT_SKIP_IF([[test -z "$CONF_JAVAC"]])
631AT_SKIP_IF([[test -z "$CONF_JAVA"]])
095a1d11
JD
632AT_CHECK([[$SHELL ../../../javacomp.sh ]$1],
633 [[0]], [ignore], [ignore])])
67a25fed 634
2d40532b
AD
635# AT_LANG_COMPILE(OUTPUT, [SOURCES = OUTPUT.c]
636# --------------------------------------------
91ce0b3a
AD
637# Compile SOURCES into OUTPUT. Skip if compiler does not work.
638#
639# If OUTPUT does not contain '.', assume that we are linking too,
640# otherwise pass "-c"; this is a hack. The default SOURCES is OUTPUT
641# with trailing .o removed, and ".c"/".cc" appended.
2d40532b
AD
642m4_define([AT_LANG_COMPILE],
643[m4_case(AT_LANG,
644[c], [AT_COMPILE([$1], [$2])],
05a7b6ec 645[c++], [AT_COMPILE_CXX([$1], [$2])],
2d40532b
AD
646[java], [AT_JAVA_COMPILE([$1.java], [$2])],
647 [m4_fatal([unknown language: ]m4_defn([AT_LANG]))])[]dnl
648])
649
6aef2e01
AD
650# AT_FULL_COMPILE(OUTPUT, [OTHER1], [OTHER2])
651# -------------------------------------------
095a1d11
JD
652# Compile OUTPUT.y to OUTPUT.c, OUTPUT.cc, or OUTPUT.java, and then
653# compile it to OUTPUT or OUTPUT.class. If OTHER is specified, compile
654# OUTPUT-OTHER.c, OUTPUT-OTHER.cc, or OUTPUT-OTHER.java to OUTPUT or
655# OUTPUT.java along with it. Relies on AT_SKEL_CC_IF and
656# AT_SKEL_JAVA_IF.
2d40532b
AD
657m4_define([AT_FULL_COMPILE],
658[m4_case(AT_LANG,
659[java],
660 [AT_BISON_CHECK([-o $1.java $1.y])
661 AT_LANG_COMPILE([$1],
662 m4_join([ ],
663 [$1.java],
664 m4_ifval($2, [[$1-$2.java]]),
665 m4_ifval($3, [[$1-$3.java]])))],
05a7b6ec 666[c++],
2d40532b
AD
667 [AT_BISON_CHECK([-o $1.cc $1.y])
668 AT_LANG_COMPILE([$1],
669 m4_join([ ],
670 [$1.cc],
671 m4_ifval($2, [[$1-$2.cc]]),
672 m4_ifval($3, [[$1-$3.cc]])))],
673[c],
674 [AT_BISON_CHECK([-o $1.c $1.y])
675 AT_LANG_COMPILE([$1],
676 m4_join([ ],
677 [$1.c],
678 m4_ifval($2, [[$1-$2.c]]),
679 m4_ifval($3, [[$1-$3.c]])))])
462503f8
JD
680])
681
67a25fed
AD
682
683## ---------------------------- ##
684## Running a generated parser. ##
685## ---------------------------- ##
686
95e343fe 687
e0ac9b4b
JD
688# AT_PARSER_CHECK(COMMAND, EXIT-STATUS, EXPOUT, EXPERR, [PRE])
689# ------------------------------------------------------------
67a25fed 690# So that we can run `./testsuite PREPARSER='valgrind -q' for instance.
95e343fe
AD
691#
692# Get rid of spurious messages when compiled with --coverage:
693# +profiling:/[...]/lib/fprintf.gcda:Merge mismatch for summaries
67a25fed 694m4_define([AT_PARSER_CHECK],
95e343fe
AD
695[AT_CHECK([$5 $PREPARSER $1], [$2], [$3], [stderr])
696AT_CHECK([sed >&2 -e '/^profiling:.*:Merge mismatch for summaries/d' stderr],
697 [0], [], [$4])
698])
699
1f7a61ff 700
095a1d11
JD
701# AT_JAVA_PARSER_CHECK(COMMAND, EXIT-STATUS, EXPOUT, EXPERR, [PRE])
702# -----------------------------------------------------------------
703m4_define([AT_JAVA_PARSER_CHECK],
704[AT_CHECK([$5[ $SHELL ../../../javaexec.sh ]$1], [$2], [$3], [$4])])
705
95e343fe 706
03c07b03
JD
707# AT_TEST_TABLES_AND_PARSE(TITLE, COND-VALUE, TEST-SPEC,
708# DECLS, GRAMMAR, INPUT,
709# BISON-STDERR, TABLES-OR-LAST-STATE,
710# [OTHER-CHECKS],
711# [PARSER-EXIT-VALUE],
712# [PARSER-STDOUT], [PARSER-STDERR])
713# -------------------------------------------------------------
714# Using TITLE as the test group title, check the generated parser tables
715# and parser for a specified grammar file under a condition labeled by
716# COND-VALUE.
717#
718# TEST-SPEC is a comma-delimited list of attributes of this test. Each
719# recognized attribute is described below where it is relevant.
720#
721# Insert DECLS and GRAMMAR into the declarations and grammar section of
722# the grammar file. Insert basic yyerror, yylex, and main function
723# definitions as well. Hardcode yylex to return the (possibly empty)
724# comma-delimited series of tokens in INPUT followed by token 0.
725#
726# If TEST-SPEC contains the attribute no-xml, then invoke bison using
727# AT_BISON_CHECK_NO_XML. Otherwise, invoke bison using AT_BISON_CHECK.
728# On the bison command-line, specify `--report=all --defines'. Check
729# that Bison exits with value 0, has no stdout, and has stderr
730# BISON-STDERR.
731#
732# If TEST-SPEC contains the attribute `last-state', check that the value
733# of TABLES-OR-LAST-STATE is the index of the last state generated for
734# the grammar; in other words, check the number of states (minus one).
735# Otherwise, check that everything in the `.output' file starting with
736# the definition of state 0 is the same as the entire value of
737# TABLES-OR-LAST-STATE.
738#
739# Expand the M4 in OTHER-CHECKS to perform additional checks of the
740# `.output' file, which is named `input.output', and/or grammar file,
741# which is named `input.y'.
742#
743# Finally, compile the generated parser and then run it using
744# AT_PARSER_CHECK with PARSER-EXIT-VALUE, PARSER-STDOUT, and
745# PARSER-STDERR as the 2nd-4th arguments.
746#
747# As a precondition, you must properly double-quote all arguments that
748# are to be interpreted as strings.
749#
750# AT_COND_CASE (when appearing in single-quoted segments of arguments)
751# invokes m4_case with its own arguments but COND-VALUE inserted as the
752# first argument. This is useful, for example, when wrapping multiple
753# AT_TEST_TABLES_AND_PARSE invocations, each representing a different
754# condition, in another macro.
755#
756# For example:
757#
758# # AT_TEST_SYNTAX_ERROR(DESCRIPTION, DECLS, GRAMMAR, INPUT, LAST-STATE,
759# # PARSER-EXIT-VALUE, PARSER-STDOUT, PARSER-STDERR)
760# # ---------------------------------------------------------------------
761# m4_define([AT_TEST_SYNTAX_ERROR],
762# [
763# AT_TEST_TABLES_AND_PARSE([$1[ with %error-verbose]], [[verbose]],
764# [[last-state]],
765# [[%error-verbose ]$2], [$3], [$4],
766# [[]], [$5], [], [$6], [$7], [$8])
767# AT_TEST_TABLES_AND_PARSE([$1[ with no %error-verbose]], [[no verbose]],
768# [[last-state]],
769# [$2], [$3], [$4],
770# [[]], [$5], [], [$6], [$7], [$8])
771# ])
772#
773# AT_TEST_SYNTAX_ERROR([[Single Char Grammar]],
774# [[%token 'b']], [[start: 'a' ;]], [['a', 'b']],
775# [[3]],
776# [[1]], [[]],
777# [AT_COND_CASE([[no verbose]],
778# [[syntax error
779# ]],
780# [[syntax error, unexpected 'b', expecting $end
781# ]])])
782m4_define([AT_TEST_TABLES_AND_PARSE],
cba97506 783[m4_pushdef([AT_COND_CASE], [m4_case([$2], $][@)])
03c07b03 784
cba97506 785AT_SETUP([$1])
55f48c48 786AT_BISON_OPTION_PUSHDEFS([$4])
03c07b03
JD
787AT_DATA_GRAMMAR([[input.y]],
788[[%code {
789 #include <stdio.h>
55f48c48
AD
790 ]AT_YYERROR_DECLARE[
791 ]AT_YYLEX_DECLARE[
03c07b03
JD
792}
793
cba97506 794]$4[
03c07b03
JD
795
796%%
797
cba97506 798]$5[
03c07b03
JD
799
800%%
55f48c48 801]AT_YYERROR_DEFINE[
03c07b03
JD
802static int
803yylex (void)
804{
805 static int const input[] = {
cba97506 806 ]m4_if([$6], [], [], [$6], [[]], [], [$6[, ]])[0
03c07b03
JD
807 };
808 static int const *inputp = input;
809 return *inputp++;
810}
811
812int
813main (void)
814{
815 return yyparse ();
816}
817]])
818
cba97506
JD
819# In some versions of Autoconf, AT_CHECK invokes AS_ESCAPE before
820# expanding macros, so it corrupts some special characters in the
821# macros. To avoid this, expand now and pass it the result with proper
cbdb6d91 822# string quotation. Assume args 7 through 12 expand to properly quoted
cba97506 823# strings.
03c07b03 824
cba97506 825m4_if(m4_index(m4_quote($3), [no-xml]), -1,
03c07b03
JD
826 [AT_BISON_CHECK],
827 [AT_BISON_CHECK_NO_XML])([[--report=all --defines -o input.c input.y]],
cba97506 828 [0], [], m4_dquote($7))
03c07b03 829
cba97506 830m4_if(m4_index(m4_quote($3), [last-state]), -1,
03c07b03 831 [AT_CHECK([[sed -n '/^state 0$/,$p' input.output]], [[0]],
cba97506 832 m4_dquote($8))],
03c07b03 833 [AT_CHECK([[sed -n 's/^state //p' input.output | tail -1]], [[0]],
cba97506 834 m4_dquote($8)[[
03c07b03 835]])])
03c07b03 836
cba97506 837$9
03c07b03 838
bbaf618c
AD
839# Canonical LR generates very large tables, resulting in very long
840# files with #line directives that may overflow what the standards
841# (C90 and C++98) guarantee: 32767. In that case, GCC's -pedantic
842# will issue an error.
843#
844# There is no "" around `wc` since some indent the result.
845m4_bmatch([$4], [%define lr.type canonical-lr],
846[if test 32767 -lt `wc -l < input.c`; then
847 CFLAGS=`echo " $CFLAGS " | sed -e 's/ -pedantic //'`
848 CXXFLAGS=`echo " $CXXFLAGS " | sed -e 's/ -pedantic //'`
849fi])
03c07b03
JD
850AT_COMPILE([[input]])
851
cba97506
JD
852AT_PARSER_CHECK([[./input]],
853 m4_ifval([$10], [m4_dquote($10)]),
854 m4_ifval([$11], [m4_dquote($11)]),
855 m4_ifval([$12], [m4_dquote($12)]))
03c07b03 856
55f48c48 857AT_BISON_OPTION_POPDEFS
03c07b03
JD
858AT_CLEANUP
859
860m4_popdef([AT_COND_CASE])])
1f7a61ff
AD
861
862
863
864## ----------------------- ##
865## Launch the test suite. ##
866## ----------------------- ##
867
868AT_INIT
869
c84134b6
AD
870# Cannot assign CC and CFLAGS here, since atlocal is loaded after
871# options are processed, so we don't know the value of CXX and
872# CXXFLAGS yet.
873#
874# Note that it also means that command line values for CXX and
875# CXXFLAGS will not be propagated to CC and CFLAGS.
876AT_ARG_OPTION([compile-c-with-cxx],
877 [compile C parsers with the C++ compiler])
878
879AT_COLOR_TESTS
880
1f7a61ff 881AT_TESTED([bison])