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