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