portability: beware of max () with MSVC
[bison.git] / tests / push.at
blob16303777bfd2f4a6665f5908f2ec2f41e5dab5a8
1 # Checking Push Parsing.                            -*- Autotest -*-
3 # Copyright (C) 2007, 2009-2015, 2018-2020 Free Software Foundation,
4 # Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
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.
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 AT_BANNER([[Push Parsing Tests]])
21 ## -------------------------------- ##
22 ## Memory Leak for Early Deletion.  ##
23 ## -------------------------------- ##
25 AT_SETUP([[Memory Leak for Early Deletion]])
27 # Requires Valgrind.
28 AT_BISON_OPTION_PUSHDEFS
29 AT_DATA_GRAMMAR([[input.y]],
32   #include <assert.h>
33   #include <stdio.h>
34   #define YYINITDEPTH 1
35 ]AT_YYERROR_DECLARE[
38 %define api.pure
39 %define api.push-pull push
43 start: 'a' 'b' 'c' ;
47 ]AT_YYERROR_DEFINE[
49 int
50 main (void)
52   yypstate *ps;
54   /* Make sure we don't try to free ps->yyss in this case.  */
55   ps = yypstate_new ();
56   yypstate_delete (ps);
58   /* yypstate_delete used to leak ps->yyss if the stack was reallocated but the
59      parse did not return on success, syntax error, or memory exhaustion.  */
60   ps = yypstate_new ();
61   assert (yypush_parse (ps, 'a', YY_NULLPTR) == YYPUSH_MORE);
62   yypstate_delete (ps);
64   ps = yypstate_new ();
65   assert (yypush_parse (ps, 'a', YY_NULLPTR) == YYPUSH_MORE);
66   assert (yypush_parse (ps, 'b', YY_NULLPTR) == YYPUSH_MORE);
67   yypstate_delete (ps);
69   return 0;
71 ]])
72 AT_BISON_OPTION_POPDEFS
74 AT_BISON_CHECK([[-o input.c input.y]])
75 AT_COMPILE([[input]])
76 AT_PARSER_CHECK([[input]])
78 AT_CLEANUP
80 ## --------------------------- ##
81 ## Multiple impure instances.  ##
82 ## --------------------------- ##
84 AT_SETUP([[Multiple impure instances]])
86 m4_pushdef([AT_MULTIPLE_IMPURE_INSTANCES_CHECK], [
87 AT_BISON_OPTION_PUSHDEFS([%define api.push-pull $1])
88 AT_DATA_GRAMMAR([[input.y]],
91   #include <assert.h>
92   #include <stdio.h>
93 ]AT_YYERROR_DECLARE[
94 ]m4_if([$1], [[both]], [AT_YYLEX_DECLARE([])])[
97 %define api.push-pull ]$1[
101 start: ;
104 ]AT_YYERROR_DEFINE[
105 ]m4_if([$1], [[both]], [AT_YYLEX_DEFINE])[
108 main (void)
110   int i;
111   for (i = 0; i < 2; ++i)
112     {
113       yypstate *ps = yypstate_new ();
114       assert (ps);
115       assert (yypstate_new () == YY_NULLPTR);
116       ]m4_if([$1], [[both]], [[assert (yyparse () == 2)]])[;
117       yychar = 0;
118       assert (yypush_parse (ps) == 0);
119       assert (yypstate_new () == YY_NULLPTR);
120       ]m4_if([$1], [[both]], [[assert (yyparse () == 2)]])[;
121       yypstate_delete (ps);
122     }
124   return 0;
128 AT_BISON_CHECK([[-o input.c input.y]])
129 AT_COMPILE([[input]])
130 AT_PARSER_CHECK([[input]])
131 AT_BISON_OPTION_POPDEFS
134 AT_MULTIPLE_IMPURE_INSTANCES_CHECK([[both]])
135 AT_MULTIPLE_IMPURE_INSTANCES_CHECK([[push]])
137 m4_popdef([AT_MULTIPLE_IMPURE_INSTANCES_CHECK])
139 AT_CLEANUP
141 ## ----------------------- ##
142 ## Unsupported Skeletons.  ##
143 ## ----------------------- ##
145 AT_SETUP([[Unsupported Skeletons]])
147 AT_BISON_OPTION_PUSHDEFS
148 AT_DATA([[input.y]],
149 [[%glr-parser
150 %define api.push-pull push
152 start: ;
154 AT_BISON_OPTION_POPDEFS
156 AT_BISON_CHECK([[input.y]], [[1]], [],
157 [[input.y:2.1-26: error: %define variable 'api.push-pull' is not used
160 AT_CLEANUP