1 # Checking skeleton support. -*- Autotest -*-
3 # Copyright (C) 2007, 2009-2015, 2018-2020 Free Software Foundation,
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]])
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
43 AT_DATA([[tmp/input-gram.y]],
44 [[%skeleton "./skel.c"
45 %define test "Hello World"
50 AT_DATA([[input-gram.y]],
51 [[%skeleton "./skel.c"
52 %define test "Hello World"
57 AT_DATA([[tmp/input-cmd-line.y]],
58 [[%define test "Hello World"
63 AT_BISON_CHECK([[tmp/input-gram.y]])
64 AT_CHECK([[cat input-gram.tab.c]], [[0]],
68 AT_BISON_CHECK([[input-gram.y]])
69 AT_CHECK([[cat input-gram.tab.c]], [[0]],
70 [[Hello World -- Local
73 AT_BISON_CHECK([[--skeleton=tmp/skel.c tmp/input-cmd-line.y]])
74 AT_CHECK([[cat input-cmd-line.tab.c]], [[0]],
81 ## ------------------------------- ##
82 ## Installed skeleton file names. ##
83 ## ------------------------------- ##
85 AT_SETUP([[Installed skeleton file names]])
87 AT_BISON_OPTION_PUSHDEFS
95 %define parse.error verbose
113 AT_DATA_GRAMMAR([[input-cmd-line.y]],
116 AT_DATA_GRAMMAR([[input-gram.y]],
117 [[%skeleton "yacc.c"]
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
134 AT_BISON_OPTION_POPDEFS
138 ## ------------------------------------------------------ ##
139 ## %define Boolean variables: invalid skeleton defaults. ##
140 ## ------------------------------------------------------ ##
142 AT_SETUP([[%define Boolean variables: invalid skeleton defaults]])
145 [[b4_percent_define_default([[foo]], [[bogus value]])
146 b4_percent_define_flag_if([[foo]])
150 [[%skeleton "./skel.c"
155 AT_BISON_CHECK([[input.y]], [[1]], [[]],
156 [[<skeleton default value>: error: invalid value for %define Boolean variable 'foo'
162 ## --------------------------------------------- ##
163 ## Complaining during macro argument expansion. ##
164 ## --------------------------------------------- ##
166 AT_SETUP([[Complaining during macro argument expansion]])
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"
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
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"
209 AT_BISON_CHECK([[input2.y]], [[1]], [[]],
210 [[foof.y:12.11-100.122: fatal error: foofat fubar
214 [[b4_complain_at(b4_percent_define_get_loc([[bogus]]), [[bad value]])
217 AT_DATA([[input3.y]],
218 [[%skeleton "./skel3.c"
223 AT_BISON_CHECK([[input3.y]], [[1]], [[]],
224 [[input3.y: fatal error: b4_percent_define_get_loc: undefined %define variable 'bogus'
228 [[b4_warn_at(b4_percent_define_get_syncline([[bogus]]), [[bad value]])
231 AT_DATA([[input4.y]],
232 [[%skeleton "./skel4.c"
237 AT_BISON_CHECK([[input4.y]], [[1]], [[]],
238 [[input4.y: fatal error: b4_percent_define_get_syncline: undefined %define variable 'bogus'
244 ## --------------------------------------- ##
245 ## Fatal errors make M4 exit immediately. ##
246 ## --------------------------------------- ##
248 AT_SETUP([[Fatal errors make M4 exit immediately]])
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"
262 AT_BISON_CHECK([[input1.y]], [[1]], [[]],
263 [[input1.y: error: non-fatal error
264 input1.y: fatal error: M4 should exit immediately here
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"
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
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
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]],
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]])
317 [[%skeleton "./skel.c"
322 AT_BISON_CHECK([[input.y]], [[1]], [[]],
323 [[input.y: fatal error: too many arguments for @output directive in skeleton