From 3ef9fa8f83316f7955babee666546feb5d9bdefc Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 15 Jan 2013 18:29:45 +0100 Subject: [PATCH] tests: factor the definition of main MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit With Théophile Ranquet. * tests/local.at (AT_MAIN_DEFINE): New. (AT_YYERROR_DEFINE): Improve formatting. * tests/actions.at, tests/c++.at, tests/conflicts.at, * tests/glr-regression.at, tests/input.at, tests/regression.at, * tests/skeletons.at, tests/torture.at: Adjust. * tests/c++.at: Add missing %skeleton for a PUSHDEFS, and a missing PUSH/POPDEFS for another test. --- tests/actions.at | 44 +++++++---------------------------------- tests/c++.at | 33 +++++++++++-------------------- tests/conflicts.at | 36 +++++---------------------------- tests/glr-regression.at | 39 +++++++++--------------------------- tests/input.at | 7 +------ tests/local.at | 38 ++++++++++++++++++++++++++++++++++- tests/regression.at | 34 +++++-------------------------- tests/skeletons.at | 7 +------ tests/torture.at | 22 +++------------------ 9 files changed, 79 insertions(+), 181 deletions(-) diff --git a/tests/actions.at b/tests/actions.at index f054c313..804d7d37 100644 --- a/tests/actions.at +++ b/tests/actions.at @@ -52,11 +52,7 @@ exp: { putchar ('0'); } %% ]AT_YYERROR_DEFINE[ ]AT_YYLEX_DEFINE(["123456789"])[ -int -main (void) -{ - return yyparse (); -} +]AT_MAIN_DEFINE[ ]]) AT_BISON_OPTION_POPDEFS @@ -295,11 +291,7 @@ sum_of_the_five_previous_values: %% ]AT_YYERROR_DEFINE[ ]AT_YYLEX_DEFINE[ -int -main (void) -{ - return yyparse (); -} +]AT_MAIN_DEFINE[ ]]) AT_BISON_CHECK([-d -v -o input.c input.y], 0) @@ -330,11 +322,7 @@ sum: { printf ("%d\n", $0.val + $-1.val + $-2.val); } ; %% ]AT_YYERROR_DEFINE[ ]AT_YYLEX_DEFINE[ -int -main (void) -{ - return yyparse (); -} +]AT_MAIN_DEFINE[ ]]) AT_FULL_COMPILE([input]) @@ -1256,11 +1244,7 @@ start: { USE($$); } ; %% ]AT_YYERROR_DEFINE[ ]AT_YYLEX_DEFINE[ -int -main (void) -{ - return yyparse (); -} +]AT_MAIN_DEFINE[ ]]) AT_BISON_OPTION_POPDEFS @@ -1422,11 +1406,7 @@ yylex (void) } ]AT_YYERROR_DEFINE[ -int -main (void) -{ - return yyparse (); -} +]AT_MAIN_DEFINE[ ]]) AT_BISON_CHECK([[-o input.c input.y]]) @@ -1712,11 +1692,7 @@ accept: /*empty*/ { %% ]AT_YYERROR_DEFINE[ ]AT_YYLEX_DEFINE(["a"])[ -int -main (void) -{ - return yyparse (); -} +]AT_MAIN_DEFINE[ ]]) AT_BISON_OPTION_POPDEFS AT_BISON_CHECK([[-o input.c input.y]]) @@ -1763,13 +1739,7 @@ exp: %% ]AT_YYERROR_DEFINE[ ]AT_YYLEX_DEFINE(["bcd"], [*lvalp = (toknum + 1) * 10])[ - -int -main (void) -{ - yydebug = !!getenv("YYDEBUG"); - return yyparse (); -} +]AT_MAIN_DEFINE[ ]]) AT_BISON_OPTION_POPDEFS diff --git a/tests/c++.at b/tests/c++.at index 0bebe8a5..868479a6 100644 --- a/tests/c++.at +++ b/tests/c++.at @@ -163,14 +163,7 @@ namespace yy } ]AT_YYERROR_DEFINE[ - -int -main () -{ - yy::parser p; - p.set_debug_level (!!getenv ("YYDEBUG")); - return p.parse (); -} +]AT_MAIN_DEFINE[ ]]) AT_BISON_CHECK([-o list.cc list.yy]) @@ -370,6 +363,8 @@ AT_CLEANUP AT_SETUP([[Syntax error discarding no lookahead]]) +AT_BISON_OPTION_PUSHDEFS([%skeleton "lalr1.cc"]) + AT_DATA_GRAMMAR([[input.yy]], [[%skeleton "lalr1.cc" @@ -421,13 +416,9 @@ yy::parser::error (const std::string &m) std::cerr << m << std::endl; } -int -main () -{ - yy::parser parser; - return parser.parse (); -} +]AT_MAIN_DEFINE[ ]]) + AT_BISON_CHECK([[-o input.cc input.yy]]) AT_COMPILE_CXX([[input]]) # This used to print "Discarding 'a'." again at the end. @@ -437,6 +428,7 @@ Discarding 'a'. Reducing 'a'. ]]) +AT_BISON_OPTION_POPDEFS AT_CLEANUP @@ -446,6 +438,8 @@ AT_CLEANUP AT_SETUP([[Syntax error as exception]]) +AT_BISON_OPTION_PUSHDEFS([%skeleton "lalr1.cc"]) + AT_DATA_GRAMMAR([[input.yy]], [[%skeleton "lalr1.cc" @@ -499,15 +493,9 @@ yy::parser::error (const std::string &m) { std::cerr << "error: " << m << std::endl; } - -int -main () -{ - yy::parser parser; - parser.set_debug_level (!!getenv ("YYDEBUG")); - return parser.parse (); -} +]AT_MAIN_DEFINE[ ]]) + AT_BISON_CHECK([[-o input.cc input.yy]]) AT_COMPILE_CXX([[input]]) @@ -518,6 +506,7 @@ error: invalid character caught error ]]) +AT_BISON_OPTION_POPDEFS AT_CLEANUP diff --git a/tests/conflicts.at b/tests/conflicts.at index 09454813..81765aac 100644 --- a/tests/conflicts.at +++ b/tests/conflicts.at @@ -221,30 +221,9 @@ public Object getLVal () /*-------. | main. | -`-------*/]AT_SKEL_JAVA_IF([[ - -class input -{ - public static void main (String args[]) throws IOException - { - YYParser p = new YYParser (); - p.parse (); - } -}]], [AT_SKEL_CC_IF([[ - -int -main (void) -{ - yy::parser parser; - return parser.parse (); -}]], [[ - -int -main (void) -{ - return yyparse (); -}]])])[ -]]) +`-------*/ +]AT_MAIN_DEFINE +]) AT_FULL_COMPILE([[input]]) @@ -492,13 +471,8 @@ reduce-nonassoc: %prec 'a'; %% ]AT_YYERROR_DEFINE[ ]AT_YYLEX_DEFINE(["aaa"])[ - -int -main (void) -{ - return yyparse (); -} -]]) +]AT_MAIN_DEFINE +]) AT_BISON_OPTION_POPDEFS # Show canonical LR's failure. diff --git a/tests/glr-regression.at b/tests/glr-regression.at index a8809ebf..e5e758cd 100644 --- a/tests/glr-regression.at +++ b/tests/glr-regression.at @@ -326,7 +326,7 @@ int yylex (void) } int -main(int argc, char* argv[]) +main (int argc, char* argv[]) { int res; input = stdin; @@ -488,11 +488,7 @@ start: %% ]AT_YYLEX_DEFINE(["a"])[ ]AT_YYERROR_DEFINE[ -int -main (void) -{ - return yyparse () != 1; -} +]AT_MAIN_DEFINE[ ]]) AT_BISON_OPTION_POPDEFS @@ -501,7 +497,7 @@ AT_BISON_CHECK([[-o glr-regr5.c glr-regr5.y]], 0, [], ]]) AT_COMPILE([glr-regr5]) -AT_PARSER_CHECK([[./glr-regr5]], 0, [], +AT_PARSER_CHECK([[./glr-regr5]], 1, [], [syntax is ambiguous ]) @@ -540,11 +536,7 @@ start: 'a' | 'a' ; %% ]AT_YYERROR_DEFINE[ ]AT_YYLEX_DEFINE(["a"])[ -int -main (void) -{ - return yyparse () != 1; -} +]AT_MAIN_DEFINE[ ]]) AT_BISON_OPTION_POPDEFS @@ -553,7 +545,7 @@ AT_BISON_CHECK([[-o glr-regr6.c glr-regr6.y]], 0, [], ]]) AT_COMPILE([glr-regr6]) -AT_PARSER_CHECK([[./glr-regr6]], 0, +AT_PARSER_CHECK([[./glr-regr6]], 1, [Destructor called. ], [syntax is ambiguous @@ -722,12 +714,7 @@ int yylex (void) } } -int -main (void) -{ - yyparse(); - return 0; -} +]AT_MAIN_DEFINE[ ]]) AT_BISON_OPTION_POPDEFS @@ -1600,11 +1587,7 @@ yylex (YYSTYPE *lvalp, YYLTYPE *llocp) return input[toknum++]; } -int -main (void) -{ - return yyparse () != 1; -} +]AT_MAIN_DEFINE[ ]]) AT_BISON_OPTION_POPDEFS @@ -1613,7 +1596,7 @@ AT_BISON_CHECK([[-o glr-regr17.c glr-regr17.y]], 0, [], ]]) AT_COMPILE([glr-regr17]) -AT_PARSER_CHECK([[./glr-regr17]], 0, [], +AT_PARSER_CHECK([[./glr-regr17]], 1, [], [1.1-2.2: syntax is ambiguous ]) @@ -1655,11 +1638,7 @@ sym3: %merge { $$ = 0; } ; %% ]AT_YYERROR_DEFINE[ ]AT_YYLEX_DEFINE[ -int -main (void) -{ - return yyparse (); -} +]AT_MAIN_DEFINE[ ]]) AT_BISON_OPTION_POPDEFS diff --git a/tests/input.at b/tests/input.at index f3ca5d99..8127f4bf 100644 --- a/tests/input.at +++ b/tests/input.at @@ -859,12 +859,7 @@ AT_DATA([main.c], #include "input.h" int yyparse (void); - -int -main (void) -{ - return yyparse (); -} +]AT_MAIN_DEFINE[ ]]) AT_BISON_OPTION_POPDEFS diff --git a/tests/local.at b/tests/local.at index aa14ced8..d4e425d8 100644 --- a/tests/local.at +++ b/tests/local.at @@ -129,6 +129,8 @@ m4_define([_AT_BISON_OPTION_PUSHDEFS], [m4_fatal([$0: Invalid arguments: $@])])dnl m4_pushdef([AT_DEFINES_IF], [m4_bmatch([$3], [%defines], [$1], [$2])]) +m4_pushdef([AT_DEBUG_IF], +[m4_bmatch([$3], [%debug\|%define parse.trace], [$1], [$2])]) m4_pushdef([AT_SKEL_CC_IF], [m4_bmatch([$3], [%language "[Cc]\+\+"\|%skeleton "[a-z0-9]+\.cc"], [$1], [$2])]) m4_pushdef([AT_SKEL_JAVA_IF], @@ -289,6 +291,7 @@ m4_popdef([AT_SKEL_JAVA_IF]) m4_popdef([AT_GLR_CC_IF]) m4_popdef([AT_LALR1_CC_IF]) m4_popdef([AT_DEFINES_IF]) +m4_popdef([AT_DEBUG_IF]) AT_LOC_POPDEF])dnl ])# AT_BISON_OPTION_POPDEFS @@ -424,7 +427,8 @@ AT_YYERROR_SEES_LOC_IF([[ [c++], [[/* A C++ error reporting function. */ void ]AT_NAME_PREFIX[::parser::error (]AT_LOCATION_IF([[const location_type& l, ]])[const std::string& m) -{ std::cerr << ]AT_LOCATION_IF([l << ": " << ])[m << std::endl; +{ + std::cerr << ]AT_LOCATION_IF([l << ": " << ])[m << std::endl; }]], [java], [AT_LOCATION_IF([[public void yyerror (Calc.Location l, String s) { @@ -442,6 +446,38 @@ void ]) +# AT_MAIN_DEFINE +# -------------- +m4_define([AT_MAIN_DEFINE], +[m4_case(AT_LANG, +[c], +[[#include /* getenv. */ +int +main (void) +{]AT_DEBUG_IF([ + yydebug = !!getenv("YYDEBUG");])[ + return !!yyparse (); +}]], +[c++], +[[#include // getenv. +int +main (void) +{ + yy::parser p;]AT_DEBUG_IF([ + p.set_debug_level (!!getenv("YYDEBUG"));])[ + return !!p.parse (); +}]], +[java], +[[class input +{ + public static void main (String args[]) throws IOException + { + YYParser p = new YYParser (); + p.parse (); + } +}]])]) + + ## --------------- ## ## Running Bison. ## ## --------------- ## diff --git a/tests/regression.at b/tests/regression.at index bee59154..398b9498 100644 --- a/tests/regression.at +++ b/tests/regression.at @@ -464,12 +464,7 @@ exp: "a" "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"; %% ]AT_YYERROR_DEFINE[ ]AT_YYLEX_DEFINE([{ SPECIAL }])[ - -int -main (void) -{ - return yyparse (); -} +]AT_MAIN_DEFINE[ ]]) AT_BISON_OPTION_POPDEFS @@ -899,12 +894,7 @@ yyparse () return parser.parse (); } ])[ - -int -main (void) -{ - return yyparse (); -} +]AT_MAIN_DEFINE[ ]]) ])# _AT_DATA_DANCER_Y @@ -983,12 +973,7 @@ yylex (]AT_LALR1_CC_IF([int *lval], [void])[) assert (toknum < sizeof tokens / sizeof *tokens); return tokens[toknum++]; } - -int -main (void) -{ - return yyparse (); -} +]AT_MAIN_DEFINE[ ]]) ])# _AT_DATA_EXPECT2_Y @@ -1180,12 +1165,7 @@ sr_conflict: ]AT_YYERROR_DEFINE[ ]AT_YYLEX_DEFINE([{ 1, 2, 3, 0 }])[ - -int -main (void) -{ - return yyparse (); -} +]AT_MAIN_DEFINE[ ]]) AT_BISON_OPTION_POPDEFS @@ -1277,11 +1257,7 @@ syntax_error: recovery by shifting 3 tokens) in order to detect any loss of the reallocated buffer. */ ]AT_YYLEX_DEFINE(["abc"])[ -int -main (void) -{ - return yyparse (); -} +]AT_MAIN_DEFINE[ ]]) AT_BISON_OPTION_POPDEFS diff --git a/tests/skeletons.at b/tests/skeletons.at index aaa30834..68a004ec 100644 --- a/tests/skeletons.at +++ b/tests/skeletons.at @@ -106,12 +106,7 @@ yylex (void) { return 'a'; } - -int -main (void) -{ - return yyparse (); -} +]AT_MAIN_DEFINE[ ]]) AT_DATA_GRAMMAR([[input-cmd-line.y]], diff --git a/tests/torture.at b/tests/torture.at index 338c33c5..5489e919 100644 --- a/tests/torture.at +++ b/tests/torture.at @@ -115,12 +115,7 @@ yylex (void) } return inner++; } -int -main (void) -{ - yydebug = !!getenv ("YYDEBUG"); - return yyparse (); -} +]AT_MAIN_DEFINE[ EOF ]]) AT_BISON_OPTION_POPDEFS @@ -204,13 +199,7 @@ yylex (void) assert (counter++ == MAX + 1); return 0; } - -int -main (void) -{ - yydebug = !!getenv ("YYDEBUG"); - return yyparse (); -} +]AT_MAIN_DEFINE[ EOF ]]) @@ -342,12 +331,7 @@ yylex (void) return counter++; } -int -main (void) -{ - yydebug = !!getenv ("YYDEBUG"); - return yyparse (); -} +]AT_MAIN_DEFINE[ EOF ]]) -- 2.45.2