1 # Checking skeleton support. -*- Autotest -*-
3 # Copyright (C) 2007, 2009-2012 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
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.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 AT_BANNER([[Skeleton Support.]])
20 ## ------------------------------ ##
21 ## Relative skeleton file names. ##
22 ## ------------------------------ ##
24 AT_SETUP([[Relative skeleton file names]])
26 AT_CHECK([[mkdir tmp]])
28 AT_DATA([[tmp/skel.c]],
29 [[m4@&t@_divert_push(0)d@&t@nl
30 @output(b4_parser_file_name@)d@&t@nl
31 b4_percent_define_get([[test]])
36 [[m4@&t@_divert_push(0)d@&t@nl
37 @output(b4_parser_file_name@)d@&t@nl
38 b4_percent_define_get([[test]]) -- Local
42 AT_DATA([[tmp/input-gram.y]],
43 [[%skeleton "./skel.c"
44 %define test "Hello World"
49 AT_DATA([[input-gram.y]],
50 [[%skeleton "./skel.c"
51 %define test "Hello World"
56 AT_DATA([[tmp/input-cmd-line.y]],
57 [[%define test "Hello World"
62 AT_BISON_CHECK([[tmp/input-gram.y]])
63 AT_CHECK([[cat input-gram.tab.c]], [[0]],
67 AT_BISON_CHECK([[input-gram.y]])
68 AT_CHECK([[cat input-gram.tab.c]], [[0]],
69 [[Hello World -- Local
72 AT_BISON_CHECK([[--skeleton=tmp/skel.c tmp/input-cmd-line.y]])
73 AT_CHECK([[cat input-cmd-line.tab.c]], [[0]],
80 ## ------------------------------- ##
81 ## Installed skeleton file names. ##
82 ## ------------------------------- ##
84 AT_SETUP([[Installed skeleton file names]])
89 void yyerror (char const *msg);
103 yyerror (char const *msg)
105 fprintf (stderr, "%s\n", msg);
121 AT_DATA([[input-cmd-line.y]],
124 AT_DATA([[input-gram.y]],
125 [[%skeleton "yacc.c"]
128 AT_BISON_CHECK([[--skeleton=yacc.c -o input-cmd-line.c input-cmd-line.y]])
129 AT_COMPILE([[input-cmd-line]])
130 AT_PARSER_CHECK([[./input-cmd-line]], [[1]], [],
131 [[syntax error, unexpected 'a', expecting $end
134 AT_BISON_CHECK([[-o input-gram.c input-gram.y]])
135 AT_COMPILE([[input-gram]])
136 AT_PARSER_CHECK([[./input-gram]], [[1]], [],
137 [[syntax error, unexpected 'a', expecting $end
145 ## ------------------------------------------------------ ##
146 ## %define Boolean variables: invalid skeleton defaults. ##
147 ## ------------------------------------------------------ ##
149 AT_SETUP([[%define Boolean variables: invalid skeleton defaults]])
152 [[b4_percent_define_default([[foo]], [[bogus value]])
153 b4_percent_define_flag_if([[foo]])
157 [[%skeleton "./skel.c"
162 AT_BISON_CHECK([[input.y]], [[1]], [[]],
163 [[<skeleton default value>: invalid value for %define Boolean variable 'foo'
169 ## --------------------------------------------- ##
170 ## Complaining during macro argument expansion. ##
171 ## --------------------------------------------- ##
173 AT_SETUP([[Complaining during macro argument expansion]])
176 [[m4@&t@_define([foow], [b4_warn([[foow fubar]])])
177 m4@&t@_define([foowat], [b4_warn_at([[foow.y:2.3]],
178 [[foow.y:5.4]], [[foowat fubar]])])
179 m4@&t@_define([fooc], [b4_complain([[fooc fubar]])])
180 m4@&t@_define([foocat], [b4_complain_at([[fooc.y:1.1]],
181 [[fooc.y:10.6]], [[foocat fubar]])])
182 m4@&t@_define([foof], [b4_fatal([[foof fubar]])])
183 m4@&t@_if(foow, [1], [yes])
184 m4@&t@_if(foowat, [1], [yes])
185 m4@&t@_if(fooc, [1], [yes])
186 m4@&t@_if(foocat, [1], [yes])
187 m4@&t@_if(foof, [1], [yes])
190 AT_DATA([[input1.y]],
191 [[%skeleton "./skel1.c"
196 AT_BISON_CHECK([[input1.y]], [[1]], [[]],
197 [[input1.y: warning: foow fubar
198 foow.y:2.3-5.3: warning: foowat fubar
200 fooc.y:1.1-10.5: foocat fubar
201 input1.y: fatal error: foof fubar
205 [[m4@&t@_define([foofat], [b4_fatal_at([[foof.y:12.11]],
206 [[foof.y:100.123]], [[foofat fubar]])])
207 m4@&t@_if(foofat, [1], [yes])
210 AT_DATA([[input2.y]],
211 [[%skeleton "./skel2.c"
216 AT_BISON_CHECK([[input2.y]], [[1]], [[]],
217 [[foof.y:12.11-100.122: fatal error: foofat fubar
221 [[b4_complain_at(b4_percent_define_get_loc([[bogus]]), [[bad value]])
224 AT_DATA([[input3.y]],
225 [[%skeleton "./skel3.c"
230 AT_BISON_CHECK([[input3.y]], [[1]], [[]],
231 [[input3.y: fatal error: undefined %define variable 'bogus' passed to b4_percent_define_get_loc
235 [[b4_warn_at(b4_percent_define_get_syncline([[bogus]]), [[bad value]])
238 AT_DATA([[input4.y]],
239 [[%skeleton "./skel4.c"
244 AT_BISON_CHECK([[input4.y]], [[1]], [[]],
245 [[input4.y: fatal error: undefined %define variable 'bogus' passed to b4_percent_define_get_syncline
251 ## --------------------------------------- ##
252 ## Fatal errors make M4 exit immediately. ##
253 ## --------------------------------------- ##
255 AT_SETUP([[Fatal errors make M4 exit immediately]])
258 [[b4_complain([[non-fatal error]])
259 b4_fatal([[M4 should exit immediately here]])
260 m4@&t@_fatal([this should never be evaluated])
263 AT_DATA([[input1.y]],
264 [[%skeleton "./skel1.c"
269 AT_BISON_CHECK([[input1.y]], [[1]], [[]],
270 [[input1.y: non-fatal error
271 input1.y: fatal error: M4 should exit immediately here
275 [[b4_warn([[morning]])
276 b4_fatal_at([[foo.y:1.5]], [[foo.y:1.7]], [[M4 should exit immediately here]])
277 m4@&t@_fatal([this should never be evaluated])
280 AT_DATA([[input2.y]],
281 [[%skeleton "./skel2.c"
286 AT_BISON_CHECK([[input2.y]], [[1]], [[]],
287 [[input2.y: warning: morning
288 foo.y:1.5-6: fatal error: M4 should exit immediately here
294 ## ------------------------------------------------ ##
295 ## Fatal errors but M4 continues producing output. ##
296 ## ------------------------------------------------ ##
298 # At one time, if Bison encountered a fatal error during M4 processing,
299 # Bison failed to drain M4's output pipe. The result was a SIGPIPE.
300 # On some platforms, the default disposition for SIGPIPE is terminate,
301 # which was fine. On others, it's ignore, which caused M4 to report
302 # the broken pipe to the user, but we don't want to bother the user with
305 # There is a race condition somewhere. That is, before the associated
306 # fix, running this test group many times in a row would occasionally
307 # produce a pass among all the failures.
309 AT_SETUP([[Fatal errors but M4 continues producing output]])
311 AT_DATA([[gen-skel.pl]],
316 print "${M4}_divert_push(0)$DNL\n";
317 print '@output(@,@)', "\n";
318 (print "garbage"x10, "\n") for (1..1000);
319 print "${M4}_divert_pop(0)\n";
321 AT_CHECK([[perl gen-skel.pl > skel.c || exit 77]])
324 [[%skeleton "./skel.c"
329 AT_BISON_CHECK([[input.y]], [[1]], [[]],
330 [[input.y: fatal error: too many arguments for @output directive in skeleton