]> git.saurik.com Git - bison.git/blame - tests/push.at
package: a bit of trouble shooting indications
[bison.git] / tests / push.at
CommitLineData
eb1b0740 1# Checking Push Parsing. -*- Autotest -*-
6e30ede8 2
3209eb1c 3# Copyright (C) 2007, 2009-2015 Free Software Foundation, Inc.
eb1b0740 4
f16b0819 5# This program is free software: you can redistribute it and/or modify
eb1b0740 6# it under the terms of the GNU General Public License as published by
f16b0819
PE
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
eb1b0740
JD
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
f16b0819 14#
eb1b0740 15# You should have received a copy of the GNU General Public License
f16b0819 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
eb1b0740
JD
17
18AT_BANNER([[Push Parsing Tests]])
19
d93b5f50
JD
20## -------------------------------- ##
21## Memory Leak for Early Deletion. ##
22## -------------------------------- ##
eb1b0740 23
d93b5f50 24AT_SETUP([[Memory Leak for Early Deletion]])
eb1b0740
JD
25
26# Requires Valgrind.
290a8ff2 27AT_BISON_OPTION_PUSHDEFS
eb1b0740
JD
28AT_DATA_GRAMMAR([[input.y]],
29[[
30%{
31 #include <assert.h>
32 #include <stdio.h>
33 #define YYINITDEPTH 1
290a8ff2 34]AT_YYERROR_DECLARE[
eb1b0740
JD
35%}
36
290a8ff2
AD
37%define api.pure
38%define api.push-pull push
eb1b0740
JD
39
40%%
41
42start: 'a' 'b' 'c' ;
43
44%%
45
290a8ff2 46]AT_YYERROR_DEFINE[
eb1b0740
JD
47
48int
49main (void)
50{
5d31a216
JD
51 yypstate *ps;
52
53 /* Make sure we don't try to free ps->yyss in this case. */
54 ps = yypstate_new ();
55 yypstate_delete (ps);
56
57 /* yypstate_delete used to leak ps->yyss if the stack was reallocated but the
58 parse did not return on success, syntax error, or memory exhaustion. */
59 ps = yypstate_new ();
8d0b7cef 60 assert (yypush_parse (ps, 'a', YY_NULLPTR) == YYPUSH_MORE);
5d31a216
JD
61 yypstate_delete (ps);
62
63 ps = yypstate_new ();
8d0b7cef
AD
64 assert (yypush_parse (ps, 'a', YY_NULLPTR) == YYPUSH_MORE);
65 assert (yypush_parse (ps, 'b', YY_NULLPTR) == YYPUSH_MORE);
5d31a216 66 yypstate_delete (ps);
eb1b0740
JD
67
68 return 0;
69}
70]])
290a8ff2 71AT_BISON_OPTION_POPDEFS
eb1b0740 72
da730230 73AT_BISON_CHECK([[-o input.c input.y]])
eb1b0740
JD
74AT_COMPILE([[input]])
75AT_PARSER_CHECK([[./input]])
76
77AT_CLEANUP
1b17b01d 78
d93b5f50
JD
79## --------------------------- ##
80## Multiple impure instances. ##
81## --------------------------- ##
1b17b01d 82
d93b5f50 83AT_SETUP([[Multiple impure instances]])
1b17b01d 84
333e670c 85m4_pushdef([AT_MULTIPLE_IMPURE_INSTANCES_CHECK], [
290a8ff2 86AT_BISON_OPTION_PUSHDEFS([%define api.push-pull $1])
1b17b01d
JD
87AT_DATA_GRAMMAR([[input.y]],
88[[
89%{
90 #include <assert.h>
91 #include <stdio.h>
290a8ff2
AD
92]AT_YYERROR_DECLARE[
93]m4_if([$1], [[both]], [AT_YYLEX_DECLARE([])])[
1b17b01d
JD
94%}
95
f37495f6 96%define api.push-pull ]$1[
1b17b01d
JD
97
98%%
99
100start: ;
101
102%%
290a8ff2 103]AT_YYERROR_DEFINE[
95361618 104]m4_if([$1], [[both]], [AT_YYLEX_DEFINE])[
1b17b01d
JD
105
106int
107main (void)
108{
1b17b01d 109 int i;
1b17b01d
JD
110 for (i = 0; i < 2; ++i)
111 {
290a8ff2 112 yypstate *ps = yypstate_new ();
1b17b01d 113 assert (ps);
8d0b7cef 114 assert (yypstate_new () == YY_NULLPTR);
333e670c 115 ]m4_if([$1], [[both]], [[assert (yyparse () == 2)]])[;
1b17b01d
JD
116 yychar = 0;
117 assert (yypush_parse (ps) == 0);
8d0b7cef 118 assert (yypstate_new () == YY_NULLPTR);
333e670c 119 ]m4_if([$1], [[both]], [[assert (yyparse () == 2)]])[;
1b17b01d
JD
120 yypstate_delete (ps);
121 }
122
123 return 0;
124}
125]])
126
da730230 127AT_BISON_CHECK([[-o input.c input.y]])
1b17b01d 128AT_COMPILE([[input]])
333e670c 129AT_PARSER_CHECK([[./input]])
290a8ff2 130AT_BISON_OPTION_POPDEFS
333e670c
JD
131])
132
133AT_MULTIPLE_IMPURE_INSTANCES_CHECK([[both]])
134AT_MULTIPLE_IMPURE_INSTANCES_CHECK([[push]])
135
136m4_popdef([AT_MULTIPLE_IMPURE_INSTANCES_CHECK])
1b17b01d
JD
137
138AT_CLEANUP
d782395d 139
d93b5f50
JD
140## ----------------------- ##
141## Unsupported Skeletons. ##
142## ----------------------- ##
d782395d 143
d93b5f50 144AT_SETUP([[Unsupported Skeletons]])
d782395d 145
290a8ff2 146AT_BISON_OPTION_PUSHDEFS
d782395d
JD
147AT_DATA([[input.y]],
148[[%glr-parser
f37495f6 149%define api.push-pull push
d782395d
JD
150%%
151start: ;
152]])
290a8ff2 153AT_BISON_OPTION_POPDEFS
d782395d 154
628be6c9 155AT_BISON_CHECK([[input.y]], [[1]], [],
b8e7ad58 156[[input.y:2.9-21: error: %define variable 'api.push-pull' is not used
d782395d
JD
157]])
158
159AT_CLEANUP