version 3.7.3
[bison.git] / tests / skeletons.at
blob744e57b56ca24db5ca575017bfdd2c2623194c1d
1 # Checking skeleton support.                     -*- 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([[Skeleton Support.]])
21 ## ------------------------------ ##
22 ## Relative skeleton file names.  ##
23 ## ------------------------------ ##
25 AT_SETUP([[Relative skeleton file names]])
27 AT_CHECK([[mkdir tmp]])
29 AT_DATA([[tmp/skel.c]],
30 [[m4@&t@_divert_push(0)d@&t@nl
31 @output(b4_parser_file_name@)d@&t@nl
32 b4_percent_define_get([[test]])
33 m4@&t@_divert_pop(0)
34 ]])
36 AT_DATA([[skel.c]],
37 [[m4@&t@_divert_push(0)d@&t@nl
38 @output(b4_parser_file_name@)d@&t@nl
39 b4_percent_define_get([[test]]) -- Local
40 m4@&t@_divert_pop(0)
41 ]])
43 AT_DATA([[tmp/input-gram.y]],
44 [[%skeleton "./skel.c"
45 %define test "Hello World"
47 start: ;
48 ]])
50 AT_DATA([[input-gram.y]],
51 [[%skeleton "./skel.c"
52 %define test "Hello World"
54 start: ;
55 ]])
57 AT_DATA([[tmp/input-cmd-line.y]],
58 [[%define test "Hello World"
60 start: ;
61 ]])
63 AT_BISON_CHECK([[tmp/input-gram.y]])
64 AT_CHECK([[cat input-gram.tab.c]], [[0]],
65 [[Hello World
66 ]])
68 AT_BISON_CHECK([[input-gram.y]])
69 AT_CHECK([[cat input-gram.tab.c]], [[0]],
70 [[Hello World -- Local
71 ]])
73 AT_BISON_CHECK([[--skeleton=tmp/skel.c tmp/input-cmd-line.y]])
74 AT_CHECK([[cat input-cmd-line.tab.c]], [[0]],
75 [[Hello World
76 ]])
78 AT_CLEANUP
81 ## ------------------------------- ##
82 ## Installed skeleton file names.  ##
83 ## ------------------------------- ##
85 AT_SETUP([[Installed skeleton file names]])
87 AT_BISON_OPTION_PUSHDEFS
88 m4_pushdef([AT_GRAM],
89 [[%{
90   #include <stdio.h>
91   ]AT_YYERROR_DECLARE[
92   int yylex (void);
95 %define parse.error verbose
96 %token 'a'
100 start: ;
104 ]AT_YYERROR_DEFINE[
106 yylex (void)
108   return 'a';
110 ]AT_MAIN_DEFINE[
113 AT_DATA_GRAMMAR([[input-cmd-line.y]],
114 [AT_GRAM])
116 AT_DATA_GRAMMAR([[input-gram.y]],
117 [[%skeleton "yacc.c"]
118 AT_GRAM])
120 AT_BISON_CHECK([[--skeleton=yacc.c -o input-cmd-line.c input-cmd-line.y]])
121 AT_COMPILE([[input-cmd-line]])
122 AT_PARSER_CHECK([[input-cmd-line]], [[1]], [],
123 [[syntax error, unexpected 'a', expecting end of file
126 AT_BISON_CHECK([[-o input-gram.c input-gram.y]])
127 AT_COMPILE([[input-gram]])
128 AT_PARSER_CHECK([[input-gram]], [[1]], [],
129 [[syntax error, unexpected 'a', expecting end of file
132 m4_popdef([AT_GRAM])
134 AT_BISON_OPTION_POPDEFS
135 AT_CLEANUP
138 ## ------------------------------------------------------ ##
139 ## %define Boolean variables: invalid skeleton defaults.  ##
140 ## ------------------------------------------------------ ##
142 AT_SETUP([[%define Boolean variables: invalid skeleton defaults]])
144 AT_DATA([[skel.c]],
145 [[b4_percent_define_default([[foo]], [[bogus value]])
146 b4_percent_define_flag_if([[foo]])
149 AT_DATA([[input.y]],
150 [[%skeleton "./skel.c"
152 start: ;
155 AT_BISON_CHECK([[input.y]], [[1]], [[]],
156 [[<skeleton default value>: error: invalid value for %define Boolean variable 'foo'
159 AT_CLEANUP
162 ## --------------------------------------------- ##
163 ## Complaining during macro argument expansion.  ##
164 ## --------------------------------------------- ##
166 AT_SETUP([[Complaining during macro argument expansion]])
168 AT_DATA([[skel1.c]],
169 [[m4@&t@_define([foow], [b4_warn([[foow fubar]])])
170 m4@&t@_define([foowat], [b4_warn_at([[foow.y:2.3]],
171                                     [[foow.y:5.4]], [[foowat fubar]])])
172 m4@&t@_define([fooc], [b4_complain([[fooc fubar]])])
173 m4@&t@_define([foocat], [b4_complain_at([[fooc.y:1.1]],
174                                         [[fooc.y:10.6]], [[foocat fubar]])])
175 m4@&t@_define([foof], [b4_fatal([[foof fubar]])])
176 m4@&t@_if(foow, [1], [yes])
177 m4@&t@_if(foowat, [1], [yes])
178 m4@&t@_if(fooc, [1], [yes])
179 m4@&t@_if(foocat, [1], [yes])
180 m4@&t@_if(foof, [1], [yes])
183 AT_DATA([[input1.y]],
184 [[%skeleton "./skel1.c"
186 start: ;
189 AT_BISON_CHECK([[input1.y]], [[1]], [[]],
190 [[input1.y: warning: foow fubar [-Wother]
191 foow.y:2.3-5.3: warning: foowat fubar [-Wother]
192 input1.y: error: fooc fubar
193 fooc.y:1.1-10.5: error: foocat fubar
194 input1.y: fatal error: foof fubar
197 AT_DATA([[skel2.c]],
198 [[m4@&t@_define([foofat], [b4_fatal_at([[foof.y:12.11]],
199                                        [[foof.y:100.123]], [[foofat fubar]])])
200 m4@&t@_if(foofat, [1], [yes])
203 AT_DATA([[input2.y]],
204 [[%skeleton "./skel2.c"
206 start: ;
209 AT_BISON_CHECK([[input2.y]], [[1]], [[]],
210 [[foof.y:12.11-100.122: fatal error: foofat fubar
213 AT_DATA([[skel3.c]],
214 [[b4_complain_at(b4_percent_define_get_loc([[bogus]]), [[bad value]])
217 AT_DATA([[input3.y]],
218 [[%skeleton "./skel3.c"
220 start: ;
223 AT_BISON_CHECK([[input3.y]], [[1]], [[]],
224 [[input3.y: fatal error: b4_percent_define_get_loc: undefined %define variable 'bogus'
227 AT_DATA([[skel4.c]],
228 [[b4_warn_at(b4_percent_define_get_syncline([[bogus]]), [[bad value]])
231 AT_DATA([[input4.y]],
232 [[%skeleton "./skel4.c"
234 start: ;
237 AT_BISON_CHECK([[input4.y]], [[1]], [[]],
238 [[input4.y: fatal error: b4_percent_define_get_syncline: undefined %define variable 'bogus'
241 AT_CLEANUP
244 ## --------------------------------------- ##
245 ## Fatal errors make M4 exit immediately.  ##
246 ## --------------------------------------- ##
248 AT_SETUP([[Fatal errors make M4 exit immediately]])
250 AT_DATA([[skel1.c]],
251 [[b4_complain([[non-fatal error]])
252 b4_fatal([[M4 should exit immediately here]])
253 m4@&t@_fatal([this should never be evaluated])
256 AT_DATA([[input1.y]],
257 [[%skeleton "./skel1.c"
259 start: ;
262 AT_BISON_CHECK([[input1.y]], [[1]], [[]],
263 [[input1.y: error: non-fatal error
264 input1.y: fatal error: M4 should exit immediately here
267 AT_DATA([[skel2.c]],
268 [[b4_warn([[morning]])
269 b4_fatal_at([[foo.y:1.5]], [[foo.y:1.7]], [[M4 should exit immediately here]])
270 m4@&t@_fatal([this should never be evaluated])
273 AT_DATA([[input2.y]],
274 [[%skeleton "./skel2.c"
276 start: ;
279 AT_BISON_CHECK([[input2.y]], [[1]], [[]],
280 [[input2.y: warning: morning [-Wother]
281 foo.y:1.5-6: fatal error: M4 should exit immediately here
284 AT_CLEANUP
287 ## ------------------------------------------------ ##
288 ## Fatal errors but M4 continues producing output.  ##
289 ## ------------------------------------------------ ##
291 # At one time, if Bison encountered a fatal error during M4 processing,
292 # Bison failed to drain M4's output pipe.  The result was a SIGPIPE.
293 # On some platforms, the default disposition for SIGPIPE is terminate,
294 # which was fine.  On others, it's ignore, which caused M4 to report
295 # the broken pipe to the user, but we don't want to bother the user with
296 # that.
298 # There is a race condition somewhere.  That is, before the associated
299 # fix, running this test group many times in a row would occasionally
300 # produce a pass among all the failures.
302 AT_SETUP([[Fatal errors but M4 continues producing output]])
304 AT_DATA([[gen-skel.pl]],
305 [[use warnings;
306 use strict;
307 my $M4 = "m4";
308 my $DNL = "d"."nl";
309 print "${M4}_divert_push(0)$DNL\n";
310 print '@output(@,@,@)', "\n";
311 (print "garbage"x10, "\n") for (1..1000);
312 print "${M4}_divert_pop(0)\n";
314 AT_PERL_REQUIRE([[gen-skel.pl > skel.c]])
316 AT_DATA([[input.y]],
317 [[%skeleton "./skel.c"
319 start: ;
322 AT_BISON_CHECK([[input.y]], [[1]], [[]],
323 [[input.y: fatal error: too many arguments for @output directive in skeleton
326 AT_CLEANUP