]> git.saurik.com Git - bison.git/blame_incremental - tests/synclines.at
tests: be more robust to unrecognized synclines, and try to recognize xlc
[bison.git] / tests / synclines.at
... / ...
CommitLineData
1# Executing Actions. -*- Autotest -*-
2
3# Copyright (C) 2002, 2004-2005, 2007, 2009-2015 Free Software
4# Foundation, Inc.
5
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.
10#
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.
15#
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/>.
18
19AT_BANNER([[User Actions.]])
20
21
22# _AT_SYNCLINES_COMPILE(FILE)
23# ---------------------------
24# Compile FILE expecting an error, and save in the file stdout the
25# normalized output. Ignore the exit status, since some compilers
26# (e.g. c89 on IRIX 6.5) trigger warnings on '#error', instead of
27# errors.
28m4_define([_AT_SYNCLINES_COMPILE],
29[AT_CHECK([$CC $CFLAGS $CPPFLAGS -c $1], [ignore], [], [stderr])
30
31# Transform stderr into something like this:
32#
33# input.y:4: #error "4"
34#
35# In case GCC displays column information, strip it down.
36#
37# input.y:4:2: #error "4" or
38# input.y:4.2: #error "4" or
39# input.y:4:2: error: #error "4"
40# =>
41# input.y:4: #error "4"
42#
43# It may also issue more context information:
44#
45# input.y: In function 'yyparse':
46# input.y:8: #error "8"
47# =>
48# input.y:4: #error "8"
49#
50# The message may include a caret-error (indented by GCC 4.8,
51# not by clang 3.2):
52#
53# input.y:1:2: error: #error "1"
54# #error "1"
55# ^
56#
57# Possibly distcc adds its bits.
58#
59# distcc[33187] ERROR: compile (null) on localhost failed
60# syncline.c:1:2: error: #error "1"
61# distcc[33185] ERROR: compile syncline.c on localhost failed
62#
63# or even
64#
65# distcc[35882] (dcc_connect_by_name) ERROR: failed to look up host "chrisimac": Unknown host
66# distcc[35882] Warning: failed to distribute input.c to chrisimac/4, running locally instead
67#
68# The compiler might end by the number of messages issued (Clang 3.2):
69#
70# syncline.c:1:2: error: "1"
71# #error "1"
72# ^
73# 1 error generated.
74#
75# When c++ is used to compiler C, we might have more messages (Clang 3.2):
76#
77# clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated
78#
79#
80# xlc reports things like:
81#
82# "input.yy", line 80.21: 1540-0218 (S) The call does not match any parameter list for "operator<<".
83# "/usr/vacpp/include/iosfwd", line 32.6: 1506-205 (S) #error This file to be used only with IBM VisualAge C++ v4 and later compilers
84
85AT_CHECK([[$PERL -p -0777 - stderr <<\EOF
86 # 1. Remove useless lines.
87
88 # distcc clutter.
89 s/^distcc\[\d+\] .*\n//gm;
90 # c vs. c++.
91 s/^clang: warning: treating 'c' input as 'c\+\+'.*\n//gm;
92 # Function context.
93 s/^[^:]*: In function '[^']+':\n//gm;
94 # Caret error.
95 s/^ *#error.*\n *\^\n//gm;
96 # Number of errors.
97 s/^1 error generated\.\n//gm;
98
99 # 2. Normalize the lines we kept.
100
101 # xlc messages. Remove also error identifier (e.g., "1540-0218 (S)").
102 s/^"(.*?)", line ([\w.]*): \d+-\d+ \(.\) /$][1:$][2: /gm;
103 # Remove column.
104 s/^([^:]+:\d+)[.:][^:]+:(.+)$/$][1:$][2/gm;
105 # Map all combinations of "error: " and "#error: " to "#error ".
106 s/^([^:]+:\d+):( |#error|error|:)+/$][1: #error /gm;
107EOF
108]],
109 0, [stdout])
110])
111
112
113
114# AT_SYNCLINES_COMPILE(FILE)
115# --------------------------
116# Compile FILE expecting an error, and save in the file stdout the
117# normalized output. If we can't get a trustable location
118# from the compiler, just skip the test.
119#
120# It seems impossible to find a generic scheme to check the location
121# of an error. Even requiring GCC is not sufficient, since for instance
122# the version modified by Apple:
123#
124# | Reading specs from /usr/libexec/gcc/darwin/ppc/2.95.2/specs
125# | Apple Computer, Inc. version gcc-934.3, based on gcc version 2.95.2
126# | 19991024 (release) configure:2124: $? = 0
127#
128# instead of:
129#
130# | input.y:2: #error "2"
131#
132# it reports:
133#
134# | input.y:2: "2"
135# | cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode
136m4_define([AT_SYNCLINES_COMPILE],
137[# Check if we can trust location translation.
138AT_DATA([syncline.c],
139[[#error "1"
140int i; /* avoids -pedantic warning about an empty translation unit. */
141]])
142
143_AT_SYNCLINES_COMPILE([syncline.c])
144AT_CHECK([[test "`cat stdout`" = 'syncline.c:1: @%:@error "1"' || exit 77]])
145
146# Then work for real.
147_AT_SYNCLINES_COMPILE([$1])
148])
149
150
151# AT_TEST(TITLE, INPUT, ERROR-MSG)
152# --------------------------------
153# Check that compiling the parser produced from INPUT cause GCC
154# to issue ERROR-MSG.
155m4_pushdef([AT_TEST],
156[AT_SETUP([$1])
157AT_BISON_OPTION_PUSHDEFS
158
159AT_DATA([[input.y]], [$2])
160AT_BISON_CHECK([-o input.c input.y])
161AT_SYNCLINES_COMPILE([input.c])
162AT_CHECK([cat stdout], 0, [$3])
163AT_BISON_OPTION_POPDEFS
164AT_CLEANUP
165])
166
167
168## ------------------- ##
169## Prologue syncline. ##
170## ------------------- ##
171
172
173AT_TEST([Prologue syncline],
174[[%{
175#error "2"
176]AT_YYERROR_DECLARE_EXTERN[
177]AT_YYLEX_DECLARE_EXTERN[
178%}
179%%
180exp: '0';
181%%
182]],
183[input.y:2: #error "2"
184])
185
186
187## ----------------- ##
188## %union syncline. ##
189## ----------------- ##
190
191AT_TEST([%union syncline],
192[[%union {
193#error "2"
194 char dummy;
195}
196%{
197]AT_YYERROR_DECLARE_EXTERN[
198]AT_YYLEX_DECLARE_EXTERN[
199%}
200%%
201exp: '0';
202%%
203]],
204[input.y:2: #error "2"
205])
206
207
208## ---------------------- ##
209## %union name syncline. ##
210## ---------------------- ##
211
212# Check that invalid union names are properly reported in the
213# source file.
214AT_SETUP([%union name syncline])
215AT_BISON_OPTION_PUSHDEFS
216AT_DATA([[input.y]],
217[[%union break
218{
219 char dummy;
220}
221%{
222]AT_YYERROR_DECLARE_EXTERN[
223]AT_YYLEX_DECLARE_EXTERN[
224%}
225%%
226exp: '0';
227%%
228]])
229
230AT_BISON_CHECK([-o input.c input.y])
231AT_SYNCLINES_COMPILE([input.c])
232AT_CHECK([[grep '^input.y:1' stdout]], 0, [ignore])
233AT_BISON_OPTION_POPDEFS
234AT_CLEANUP
235
236
237## ----------------------- ##
238## Postprologue syncline. ##
239## ----------------------- ##
240
241AT_TEST([Postprologue syncline],
242[[%{
243]AT_YYERROR_DECLARE_EXTERN[
244]AT_YYLEX_DECLARE_EXTERN[
245%}
246%union
247{
248 int ival;
249}
250%{
251#error "10"
252%}
253%%
254exp: '0';
255%%
256]],
257[input.y:10: #error "10"
258])
259
260
261## ----------------- ##
262## Action syncline. ##
263## ----------------- ##
264
265AT_TEST([Action syncline],
266[[%{
267]AT_YYERROR_DECLARE_EXTERN[
268]AT_YYLEX_DECLARE_EXTERN[
269%}
270%%
271exp:
272{
273#error "8"
274};
275]],
276[input.y:8: #error "8"
277])
278
279
280## ------------------- ##
281## Epilogue syncline. ##
282## ------------------- ##
283
284AT_TEST([Epilogue syncline],
285[[%{
286]AT_YYERROR_DECLARE_EXTERN[
287]AT_YYLEX_DECLARE_EXTERN[
288%}
289%%
290exp: '0';
291%%
292#error "8"
293]],
294[input.y:8: #error "8"
295])
296
297## -------------------- ##
298## %code top syncline. ##
299## -------------------- ##
300
301AT_TEST([%code top syncline],
302[[%code top {
303#error "2"
304}
305%{
306]AT_YYERROR_DECLARE_EXTERN[
307]AT_YYLEX_DECLARE_EXTERN[
308%}
309%%
310exp: '0';
311%%
312]],
313[input.y:2: #error "2"
314])
315
316m4_popdef([AT_TEST])
317
318## ----------- ##
319## %no-lines. ##
320## ----------- ##
321
322m4_pushdef([AT_TEST],
323[AT_SETUP([%no-lines: $1])
324
325AT_BISON_OPTION_PUSHDEFS([%skeleton "$1" %defines])
326AT_DATA_GRAMMAR([input.y],
327[%skeleton "$1" %defines
328%{
329]AT_YYERROR_DECLARE_EXTERN[
330]AT_YYLEX_DECLARE_EXTERN[
331%}
332%%
333exp: '0'
334])
335AT_BISON_CHECK([--no-lines -o input.AT_SKEL_CC_IF([cc], [c]) -d input.y])
336AT_CHECK([[grep '#line' ]AT_SKEL_CC_IF([*.cc *.hh], [*.c *.h])], 1)
337AT_BISON_OPTION_POPDEFS
338
339AT_CLEANUP
340])
341
342AT_TEST([yacc.c])
343AT_TEST([glr.c])
344AT_TEST([lalr1.cc])
345AT_TEST([glr.cc])
346
347m4_popdef([AT_TEST])