]> git.saurik.com Git - bison.git/blame - tests/push.at
build: generalize etc/prefix-gnulib-mk
[bison.git] / tests / push.at
CommitLineData
eb1b0740 1# Checking Push Parsing. -*- Autotest -*-
7d424de1 2
34136e65 3# Copyright (C) 2007, 2009-2012 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
00d80a9c
JD
20## -------------------------------- ##
21## Memory Leak for Early Deletion. ##
22## -------------------------------- ##
eb1b0740 23
00d80a9c 24AT_SETUP([[Memory Leak for Early Deletion]])
eb1b0740
JD
25
26# Requires Valgrind.
27
28AT_DATA_GRAMMAR([[input.y]],
29[[
30%{
31 #include <assert.h>
32 #include <stdio.h>
33 #define YYINITDEPTH 1
34 void yyerror (char const *msg);
35%}
36
cf499cff 37%define api.pure %define api.push-pull push
eb1b0740
JD
38
39%%
40
41start: 'a' 'b' 'c' ;
42
43%%
44
45void
46yyerror (char const *msg)
47{
48 fprintf (stderr, "%s\n", msg);
49}
50
51int
52main (void)
53{
5d31a216
JD
54 yypstate *ps;
55
56 /* Make sure we don't try to free ps->yyss in this case. */
57 ps = yypstate_new ();
58 yypstate_delete (ps);
59
60 /* yypstate_delete used to leak ps->yyss if the stack was reallocated but the
61 parse did not return on success, syntax error, or memory exhaustion. */
62 ps = yypstate_new ();
63 assert (yypush_parse (ps, 'a', NULL) == YYPUSH_MORE);
64 yypstate_delete (ps);
65
66 ps = yypstate_new ();
67 assert (yypush_parse (ps, 'a', NULL) == YYPUSH_MORE);
68 assert (yypush_parse (ps, 'b', NULL) == YYPUSH_MORE);
69 yypstate_delete (ps);
eb1b0740
JD
70
71 return 0;
72}
73]])
74
da730230 75AT_BISON_CHECK([[-o input.c input.y]])
eb1b0740
JD
76AT_COMPILE([[input]])
77AT_PARSER_CHECK([[./input]])
78
79AT_CLEANUP
1b17b01d 80
00d80a9c
JD
81## --------------------------- ##
82## Multiple impure instances. ##
83## --------------------------- ##
1b17b01d 84
00d80a9c 85AT_SETUP([[Multiple impure instances]])
1b17b01d 86
333e670c 87m4_pushdef([AT_MULTIPLE_IMPURE_INSTANCES_CHECK], [
1b17b01d
JD
88AT_DATA_GRAMMAR([[input.y]],
89[[
90%{
91 #include <assert.h>
92 #include <stdio.h>
93 void yyerror (char const *msg);
94 int yylex (void);
95%}
96
cf499cff 97%define api.push-pull ]$1[
1b17b01d
JD
98
99%%
100
101start: ;
102
103%%
104
105void
106yyerror (char const *msg)
107{
108 fprintf (stderr, "%s\n", msg);
109}
110
111int
112yylex (void)
113{
114 return 0;
115}
116
117int
118main (void)
119{
120 yypstate *ps;
121 int i;
122
123 for (i = 0; i < 2; ++i)
124 {
125 ps = yypstate_new ();
126 assert (ps);
127 assert (yypstate_new () == NULL);
333e670c 128 ]m4_if([$1], [[both]], [[assert (yyparse () == 2)]])[;
1b17b01d
JD
129 yychar = 0;
130 assert (yypush_parse (ps) == 0);
131 assert (yypstate_new () == NULL);
333e670c 132 ]m4_if([$1], [[both]], [[assert (yyparse () == 2)]])[;
1b17b01d
JD
133 yypstate_delete (ps);
134 }
135
136 return 0;
137}
138]])
139
da730230 140AT_BISON_CHECK([[-o input.c input.y]])
1b17b01d 141AT_COMPILE([[input]])
333e670c
JD
142AT_PARSER_CHECK([[./input]])
143])
144
145AT_MULTIPLE_IMPURE_INSTANCES_CHECK([[both]])
146AT_MULTIPLE_IMPURE_INSTANCES_CHECK([[push]])
147
148m4_popdef([AT_MULTIPLE_IMPURE_INSTANCES_CHECK])
1b17b01d
JD
149
150AT_CLEANUP
d782395d 151
00d80a9c
JD
152## ----------------------- ##
153## Unsupported Skeletons. ##
154## ----------------------- ##
d782395d 155
00d80a9c 156AT_SETUP([[Unsupported Skeletons]])
d782395d
JD
157
158AT_DATA([[input.y]],
159[[%glr-parser
cf499cff 160%define api.push-pull push
d782395d
JD
161%%
162start: ;
163]])
164
c6abeab1 165AT_BISON_CHECK([[input.y]], [[1]], [],
4aa9d1ff 166[[input.y:2.9-21: %define variable 'api.push-pull' is not used
d782395d
JD
167]])
168
169AT_CLEANUP