rename muscle_tab.* as muscle-tab.* for consistency.
[bison/ericb.git] / tests / push.at
blob70c1fdce2062a1793376ac3b2c8af37eaa6cb19c
1 # Checking Push Parsing.                            -*- Autotest -*-
2 # Copyright (C) 2007 Free Software Foundation, Inc.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 AT_BANNER([[Push Parsing Tests]])
19 ## ---------------------------------------------- ##
20 ## Push Parsing: Memory Leak for Early Deletion.  ##
21 ## ---------------------------------------------- ##
23 AT_SETUP([[Push Parsing: Memory Leak for Early Deletion]])
25 # Requires Valgrind.
27 AT_DATA_GRAMMAR([[input.y]],
30   #include <assert.h>
31   #include <stdio.h>
32   #define YYINITDEPTH 1
33   void yyerror (char const *msg);
36 %define api.pure %define api.push_pull "push"
40 start: 'a' 'b' 'c' ;
44 void
45 yyerror (char const *msg)
47   fprintf (stderr, "%s\n", msg);
50 int
51 main (void)
53   yypstate *ps;
55   /* Make sure we don't try to free ps->yyss in this case.  */
56   ps = yypstate_new ();
57   yypstate_delete (ps);
59   /* yypstate_delete used to leak ps->yyss if the stack was reallocated but the
60      parse did not return on success, syntax error, or memory exhaustion.  */
61   ps = yypstate_new ();
62   assert (yypush_parse (ps, 'a', NULL) == YYPUSH_MORE);
63   yypstate_delete (ps);
65   ps = yypstate_new ();
66   assert (yypush_parse (ps, 'a', NULL) == YYPUSH_MORE);
67   assert (yypush_parse (ps, 'b', NULL) == YYPUSH_MORE);
68   yypstate_delete (ps);
70   return 0;
72 ]])
74 AT_BISON_CHECK([[-o input.c input.y]])
75 AT_COMPILE([[input]])
76 AT_PARSER_CHECK([[./input]])
78 AT_CLEANUP
80 ## ----------------------------------------- ##
81 ## Push Parsing: Multiple impure instances.  ##
82 ## ----------------------------------------- ##
84 AT_SETUP([[Push Parsing: Multiple impure instances]])
86 m4_pushdef([AT_MULTIPLE_IMPURE_INSTANCES_CHECK], [
87 AT_DATA_GRAMMAR([[input.y]],
90   #include <assert.h>
91   #include <stdio.h>
92   void yyerror (char const *msg);
93   int yylex (void);
96 %define api.push_pull "]$1["
100 start: ;
104 void
105 yyerror (char const *msg)
107   fprintf (stderr, "%s\n", msg);
111 yylex (void)
113   return 0;
117 main (void)
119   yypstate *ps;
120   int i;
122   for (i = 0; i < 2; ++i)
123     {
124       ps = yypstate_new ();
125       assert (ps);
126       assert (yypstate_new () == NULL);
127       ]m4_if([$1], [[both]], [[assert (yyparse () == 2)]])[;
128       yychar = 0;
129       assert (yypush_parse (ps) == 0);
130       assert (yypstate_new () == NULL);
131       ]m4_if([$1], [[both]], [[assert (yyparse () == 2)]])[;
132       yypstate_delete (ps);
133     }
135   return 0;
139 AT_BISON_CHECK([[-o input.c input.y]])
140 AT_COMPILE([[input]])
141 AT_PARSER_CHECK([[./input]])
144 AT_MULTIPLE_IMPURE_INSTANCES_CHECK([[both]])
145 AT_MULTIPLE_IMPURE_INSTANCES_CHECK([[push]])
147 m4_popdef([AT_MULTIPLE_IMPURE_INSTANCES_CHECK])
149 AT_CLEANUP
151 ## ------------------------------------- ##
152 ## Push Parsing: Unsupported Skeletons.  ##
153 ## ------------------------------------- ##
155 AT_SETUP([[Push Parsing: Unsupported Skeletons]])
157 AT_DATA([[input.y]],
158 [[%glr-parser
159 %define api.push_pull "push"
161 start: ;
164 AT_BISON_CHECK([[input.y]], [0], [],
165 [[input.y:2.9-21: warning: %define variable `api.push_pull' is not used
168 AT_CLEANUP