]> git.saurik.com Git - bison.git/blame - tests/skeletons.at
tests: improve factoring of the main function
[bison.git] / tests / skeletons.at
CommitLineData
a7867f53 1# Checking skeleton support. -*- Autotest -*-
6e30ede8 2
7d6bad19 3# Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
a7867f53 4
f16b0819 5# This program is free software: you can redistribute it and/or modify
a7867f53 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#
a7867f53
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#
a7867f53 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/>.
a7867f53 17
3eb82471 18AT_BANNER([[Skeleton Support.]])
a7867f53
JD
19
20## ------------------------------ ##
9611cfa2 21## Relative skeleton file names. ##
a7867f53
JD
22## ------------------------------ ##
23
9611cfa2 24AT_SETUP([[Relative skeleton file names]])
a7867f53
JD
25
26AT_CHECK([[mkdir tmp]])
27
28AT_DATA([[tmp/skel.c]],
29[[m4@&t@_divert_push(0)d@&t@nl
30@output(b4_parser_file_name@)d@&t@nl
31b4_percent_define_get([[test]])
32m4@&t@_divert_pop(0)
33]])
34
35AT_DATA([[skel.c]],
36[[m4@&t@_divert_push(0)d@&t@nl
37@output(b4_parser_file_name@)d@&t@nl
38b4_percent_define_get([[test]]) -- Local
39m4@&t@_divert_pop(0)
40]])
41
42AT_DATA([[tmp/input-gram.y]],
43[[%skeleton "./skel.c"
44%define test "Hello World"
45%%
46start: ;
47]])
48
49AT_DATA([[input-gram.y]],
50[[%skeleton "./skel.c"
51%define test "Hello World"
52%%
53start: ;
54]])
55
56AT_DATA([[tmp/input-cmd-line.y]],
57[[%define test "Hello World"
58%%
59start: ;
60]])
61
da730230 62AT_BISON_CHECK([[tmp/input-gram.y]])
a7867f53
JD
63AT_CHECK([[cat input-gram.tab.c]], [[0]],
64[[Hello World
65]])
66
da730230 67AT_BISON_CHECK([[input-gram.y]])
a7867f53
JD
68AT_CHECK([[cat input-gram.tab.c]], [[0]],
69[[Hello World -- Local
70]])
71
da730230 72AT_BISON_CHECK([[--skeleton=tmp/skel.c tmp/input-cmd-line.y]])
a7867f53
JD
73AT_CHECK([[cat input-cmd-line.tab.c]], [[0]],
74[[Hello World
75]])
76
77AT_CLEANUP
78
79
3eb82471 80## ------------------------------- ##
9611cfa2 81## Installed skeleton file names. ##
3eb82471 82## ------------------------------- ##
a7867f53 83
9611cfa2 84AT_SETUP([[Installed skeleton file names]])
a7867f53 85
55f48c48 86AT_BISON_OPTION_PUSHDEFS
a7867f53
JD
87m4_pushdef([AT_GRAM],
88[[%{
89 #include <stdio.h>
55f48c48 90 ]AT_YYERROR_DECLARE[
a7867f53
JD
91 int yylex (void);
92%}
93
94%error-verbose
95%token 'a'
96
97%%
98
99start: ;
100
101%%
102
55f48c48 103]AT_YYERROR_DEFINE[
a7867f53
JD
104int
105yylex (void)
106{
107 return 'a';
108}
3ef9fa8f 109]AT_MAIN_DEFINE[
a7867f53
JD
110]])
111
6ee95cd0 112AT_DATA_GRAMMAR([[input-cmd-line.y]],
a7867f53
JD
113[AT_GRAM])
114
6ee95cd0 115AT_DATA_GRAMMAR([[input-gram.y]],
a7867f53
JD
116[[%skeleton "yacc.c"]
117AT_GRAM])
118
da730230 119AT_BISON_CHECK([[--skeleton=yacc.c -o input-cmd-line.c input-cmd-line.y]])
a7867f53
JD
120AT_COMPILE([[input-cmd-line]])
121AT_PARSER_CHECK([[./input-cmd-line]], [[1]], [],
122[[syntax error, unexpected 'a', expecting $end
123]])
124
da730230 125AT_BISON_CHECK([[-o input-gram.c input-gram.y]])
a7867f53
JD
126AT_COMPILE([[input-gram]])
127AT_PARSER_CHECK([[./input-gram]], [[1]], [],
128[[syntax error, unexpected 'a', expecting $end
129]])
130
131m4_popdef([AT_GRAM])
132
55f48c48 133AT_BISON_OPTION_POPDEFS
a7867f53 134AT_CLEANUP
9611cfa2
JD
135
136
137## ------------------------------------------------------ ##
922bdd7f 138## %define Boolean variables: invalid skeleton defaults. ##
9611cfa2
JD
139## ------------------------------------------------------ ##
140
922bdd7f 141AT_SETUP([[%define Boolean variables: invalid skeleton defaults]])
9611cfa2 142
9611cfa2
JD
143AT_DATA([[skel.c]],
144[[b4_percent_define_default([[foo]], [[bogus value]])
145b4_percent_define_flag_if([[foo]])
146]])
147
148AT_DATA([[input.y]],
149[[%skeleton "./skel.c"
150%%
151start: ;
152]])
153
da730230 154AT_BISON_CHECK([[input.y]], [[1]], [[]],
b8e7ad58 155[[<skeleton default value>: error: invalid value for %define Boolean variable 'foo'
9611cfa2
JD
156]])
157
158AT_CLEANUP
159
160
7dc4a694
JD
161## --------------------------------------------- ##
162## Complaining during macro argument expansion. ##
163## --------------------------------------------- ##
164
165AT_SETUP([[Complaining during macro argument expansion]])
166
167AT_DATA([[skel1.c]],
168[[m4@&t@_define([foow], [b4_warn([[foow fubar]])])
169m4@&t@_define([foowat], [b4_warn_at([[foow.y:2.3]],
170 [[foow.y:5.4]], [[foowat fubar]])])
171m4@&t@_define([fooc], [b4_complain([[fooc fubar]])])
172m4@&t@_define([foocat], [b4_complain_at([[fooc.y:1.1]],
173 [[fooc.y:10.6]], [[foocat fubar]])])
174m4@&t@_define([foof], [b4_fatal([[foof fubar]])])
175m4@&t@_if(foow, [1], [yes])
176m4@&t@_if(foowat, [1], [yes])
177m4@&t@_if(fooc, [1], [yes])
178m4@&t@_if(foocat, [1], [yes])
179m4@&t@_if(foof, [1], [yes])
180]])
181
182AT_DATA([[input1.y]],
183[[%skeleton "./skel1.c"
184%%
185start: ;
186]])
187
da730230 188AT_BISON_CHECK([[input1.y]], [[1]], [[]],
73370a9d
VS
189[[input1.y: warning: foow fubar [-Wother]
190foow.y:2.3-5.3: warning: foowat fubar [-Wother]
b8e7ad58
TR
191input1.y: error: fooc fubar
192fooc.y:1.1-10.5: error: foocat fubar
7dc4a694
JD
193input1.y: fatal error: foof fubar
194]])
195
196AT_DATA([[skel2.c]],
197[[m4@&t@_define([foofat], [b4_fatal_at([[foof.y:12.11]],
198 [[foof.y:100.123]], [[foofat fubar]])])
199m4@&t@_if(foofat, [1], [yes])
200]])
201
202AT_DATA([[input2.y]],
203[[%skeleton "./skel2.c"
204%%
205start: ;
206]])
207
da730230 208AT_BISON_CHECK([[input2.y]], [[1]], [[]],
7dc4a694
JD
209[[foof.y:12.11-100.122: fatal error: foofat fubar
210]])
211
35b8730d
JD
212AT_DATA([[skel3.c]],
213[[b4_complain_at(b4_percent_define_get_loc([[bogus]]), [[bad value]])
214]])
215
216AT_DATA([[input3.y]],
217[[%skeleton "./skel3.c"
218%%
219start: ;
220]])
221
da730230 222AT_BISON_CHECK([[input3.y]], [[1]], [[]],
4c787a31 223[[input3.y: fatal error: b4_percent_define_get_loc: undefined %define variable 'bogus'
35b8730d
JD
224]])
225
226AT_DATA([[skel4.c]],
227[[b4_warn_at(b4_percent_define_get_syncline([[bogus]]), [[bad value]])
228]])
229
230AT_DATA([[input4.y]],
231[[%skeleton "./skel4.c"
232%%
233start: ;
234]])
235
da730230 236AT_BISON_CHECK([[input4.y]], [[1]], [[]],
4c787a31 237[[input4.y: fatal error: b4_percent_define_get_syncline: undefined %define variable 'bogus'
35b8730d
JD
238]])
239
7dc4a694
JD
240AT_CLEANUP
241
242
243## --------------------------------------- ##
244## Fatal errors make M4 exit immediately. ##
245## --------------------------------------- ##
246
247AT_SETUP([[Fatal errors make M4 exit immediately]])
248
249AT_DATA([[skel1.c]],
250[[b4_complain([[non-fatal error]])
251b4_fatal([[M4 should exit immediately here]])
252m4@&t@_fatal([this should never be evaluated])
253]])
254
255AT_DATA([[input1.y]],
256[[%skeleton "./skel1.c"
257%%
258start: ;
259]])
260
da730230 261AT_BISON_CHECK([[input1.y]], [[1]], [[]],
b8e7ad58 262[[input1.y: error: non-fatal error
7dc4a694
JD
263input1.y: fatal error: M4 should exit immediately here
264]])
265
266AT_DATA([[skel2.c]],
267[[b4_warn([[morning]])
268b4_fatal_at([[foo.y:1.5]], [[foo.y:1.7]], [[M4 should exit immediately here]])
269m4@&t@_fatal([this should never be evaluated])
270]])
271
272AT_DATA([[input2.y]],
273[[%skeleton "./skel2.c"
274%%
275start: ;
276]])
277
da730230 278AT_BISON_CHECK([[input2.y]], [[1]], [[]],
73370a9d 279[[input2.y: warning: morning [-Wother]
7dc4a694
JD
280foo.y:1.5-6: fatal error: M4 should exit immediately here
281]])
282
283AT_CLEANUP
47fa5747
JD
284
285
286## ------------------------------------------------ ##
287## Fatal errors but M4 continues producing output. ##
288## ------------------------------------------------ ##
289
290# At one time, if Bison encountered a fatal error during M4 processing,
291# Bison failed to drain M4's output pipe. The result was a SIGPIPE.
292# On some platforms, the default disposition for SIGPIPE is terminate,
293# which was fine. On others, it's ignore, which caused M4 to report
294# the broken pipe to the user, but we don't want to bother the user with
295# that.
296
297# There is a race condition somewhere. That is, before the associated
298# fix, running this test group many times in a row would occasionally
299# produce a pass among all the failures.
300
301AT_SETUP([[Fatal errors but M4 continues producing output]])
302
303AT_DATA([[gen-skel.pl]],
304[[use warnings;
305use strict;
306my $M4 = "m4";
307my $DNL = "d"."nl";
308print "${M4}_divert_push(0)$DNL\n";
309print '@output(@,@)', "\n";
310(print "garbage"x10, "\n") for (1..1000);
311print "${M4}_divert_pop(0)\n";
312]])
ff020c30 313AT_CHECK([[$PERL gen-skel.pl > skel.c || exit 77]])
47fa5747
JD
314
315AT_DATA([[input.y]],
316[[%skeleton "./skel.c"
317%%
318start: ;
319]])
320
321AT_BISON_CHECK([[input.y]], [[1]], [[]],
322[[input.y: fatal error: too many arguments for @output directive in skeleton
323]])
324
325AT_CLEANUP