]> git.saurik.com Git - bison.git/blame - tests/synclines.at
gnulib: update
[bison.git] / tests / synclines.at
CommitLineData
642cb8f8 1# Executing Actions. -*- Autotest -*-
6e30ede8 2
3209eb1c 3# Copyright (C) 2002, 2004-2005, 2007, 2009-2015 Free Software
1462fcee 4# Foundation, Inc.
642cb8f8 5
f16b0819 6# This program is free software: you can redistribute it and/or modify
642cb8f8 7# it under the terms of the GNU General Public License as published by
f16b0819
PE
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
642cb8f8
AD
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.
f16b0819 15#
642cb8f8 16# You should have received a copy of the GNU General Public License
f16b0819 17# along with this program. If not, see <http://www.gnu.org/licenses/>.
642cb8f8
AD
18
19AT_BANNER([[User Actions.]])
20
865b9df1 21
0b0370ff
AD
22# _AT_SYNCLINES_COMPILE(FILE)
23# ---------------------------
4e8d992c
AD
24# Compile FILE expecting an error, and save in the file stdout the
25# normalized output. Ignore the exit status, since some compilers
4c9b8f13 26# (e.g. c89 on IRIX 6.5) trigger warnings on '#error', instead of
4e8d992c 27# errors.
0b0370ff 28m4_define([_AT_SYNCLINES_COMPILE],
f32b346d 29[AT_CHECK([$CC $CFLAGS $CPPFLAGS -c $1], [ignore], [], [stderr])
0bb672d8
AD
30
31# Transform stderr into something like this:
32#
33# input.y:4: #error "4"
34#
865b9df1
AD
35# In case GCC displays column information, strip it down.
36#
4d1801f1
PE
37# input.y:4:2: #error "4" or
38# input.y:4.2: #error "4" or
39# input.y:4:2: error: #error "4"
865b9df1
AD
40# =>
41# input.y:4: #error "4"
42#
bdc360ae
AD
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#
2cf5f72e
AD
50# The message may include a caret-error (indented by GCC 4.8,
51# not by clang 3.2):
0bb672d8
AD
52#
53# input.y:1:2: error: #error "1"
54# #error "1"
55# ^
bdc360ae 56#
d4dcde2b 57# Possibly distcc adds its bits.
bdc360ae
AD
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
2cf5f72e
AD
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.
d4dcde2b
AD
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
0b0370ff
AD
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
009285d2
AD
84#
85# Newer GCCs go further and if the function is declared static, complain
86# that it's not used.
ff020c30 87AT_CHECK([[$PERL -p -0777 - stderr <<\EOF
2cf5f72e
AD
88 # 1. Remove useless lines.
89
90 # distcc clutter.
1914a781 91 s/^distcc\[\d+\] .*\n//gm;
d4dcde2b
AD
92 # c vs. c++.
93 s/^clang: warning: treating 'c' input as 'c\+\+'.*\n//gm;
2cf5f72e 94 # Function context.
1914a781 95 s/^[^:]*: In function '[^']+':\n//gm;
2cf5f72e
AD
96 # Caret error.
97 s/^ *#error.*\n *\^\n//gm;
98 # Number of errors.
99 s/^1 error generated\.\n//gm;
100
101 # 2. Normalize the lines we kept.
102
0b0370ff
AD
103 # xlc messages. Remove also error identifier (e.g., "1540-0218 (S)").
104 s/^"(.*?)", line ([\w.]*): \d+-\d+ \(.\) /$][1:$][2: /gm;
2cf5f72e
AD
105 # Remove column.
106 s/^([^:]+:\d+)[.:][^:]+:(.+)$/$][1:$][2/gm;
107 # Map all combinations of "error: " and "#error: " to "#error ".
108 s/^([^:]+:\d+):( |#error|error|:)+/$][1: #error /gm;
0bb672d8
AD
109EOF
110]],
1914a781 111 0, [stdout])
865b9df1
AD
112])
113
0b0370ff
AD
114
115
116# AT_SYNCLINES_COMPILE(FILE)
117# --------------------------
118# Compile FILE expecting an error, and save in the file stdout the
119# normalized output. If we can't get a trustable location
120# from the compiler, just skip the test.
121#
865b9df1
AD
122# It seems impossible to find a generic scheme to check the location
123# of an error. Even requiring GCC is not sufficient, since for instance
124# the version modified by Apple:
125#
126# | Reading specs from /usr/libexec/gcc/darwin/ppc/2.95.2/specs
127# | Apple Computer, Inc. version gcc-934.3, based on gcc version 2.95.2
128# | 19991024 (release) configure:2124: $? = 0
129#
130# instead of:
131#
132# | input.y:2: #error "2"
133#
134# it reports:
135#
136# | input.y:2: "2"
137# | cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode
0b0370ff
AD
138m4_define([AT_SYNCLINES_COMPILE],
139[# Check if we can trust location translation.
865b9df1 140AT_DATA([syncline.c],
009285d2
AD
141[[void foo (void);
142void foo (void)
a668f486 143{
009285d2 144#error "4"
a668f486 145}
865b9df1 146]])
642cb8f8 147
0b0370ff 148_AT_SYNCLINES_COMPILE([syncline.c])
009285d2 149AT_CHECK([[test "`cat stdout`" = 'syncline.c:4: @%:@error "4"' || exit 77]])
865b9df1 150
0b0370ff
AD
151# Then work for real.
152_AT_SYNCLINES_COMPILE([$1])
153])
154
155
156# AT_TEST(TITLE, INPUT, ERROR-MSG)
157# --------------------------------
158# Check that compiling the parser produced from INPUT cause GCC
159# to issue ERROR-MSG.
160m4_pushdef([AT_TEST],
161[AT_SETUP([$1])
162AT_BISON_OPTION_PUSHDEFS
163
865b9df1 164AT_DATA([[input.y]], [$2])
da730230 165AT_BISON_CHECK([-o input.c input.y])
865b9df1 166AT_SYNCLINES_COMPILE([input.c])
bdc360ae 167AT_CHECK([cat stdout], 0, [$3])
55f48c48 168AT_BISON_OPTION_POPDEFS
642cb8f8
AD
169AT_CLEANUP
170])
171
172
06f2ac78
AD
173## ------------------- ##
174## Prologue syncline. ##
175## ------------------- ##
642cb8f8
AD
176
177
06f2ac78 178AT_TEST([Prologue syncline],
642cb8f8
AD
179[[%{
180#error "2"
55f48c48
AD
181]AT_YYERROR_DECLARE_EXTERN[
182]AT_YYLEX_DECLARE_EXTERN[
642cb8f8
AD
183%}
184%%
185exp: '0';
55f48c48 186%%
642cb8f8
AD
187]],
188[input.y:2: #error "2"
189])
190
191
06f2ac78
AD
192## ----------------- ##
193## %union syncline. ##
194## ----------------- ##
642cb8f8 195
06f2ac78 196AT_TEST([%union syncline],
642cb8f8
AD
197[[%union {
198#error "2"
0f53f222 199 char dummy;
642cb8f8 200}
5683e9b2 201%{
55f48c48
AD
202]AT_YYERROR_DECLARE_EXTERN[
203]AT_YYLEX_DECLARE_EXTERN[
5683e9b2 204%}
642cb8f8
AD
205%%
206exp: '0';
55f48c48 207%%
642cb8f8
AD
208]],
209[input.y:2: #error "2"
210])
211
212
827bc59c
AD
213## ---------------------- ##
214## %union name syncline. ##
215## ---------------------- ##
216
217# Check that invalid union names are properly reported in the
218# source file.
219AT_SETUP([%union name syncline])
220AT_BISON_OPTION_PUSHDEFS
221AT_DATA([[input.y]],
222[[%union break
223{
224 char dummy;
225}
226%{
227]AT_YYERROR_DECLARE_EXTERN[
228]AT_YYLEX_DECLARE_EXTERN[
229%}
230%%
231exp: '0';
232%%
233]])
234
235AT_BISON_CHECK([-o input.c input.y])
236AT_SYNCLINES_COMPILE([input.c])
237AT_CHECK([[grep '^input.y:1' stdout]], 0, [ignore])
238AT_BISON_OPTION_POPDEFS
239AT_CLEANUP
240
241
06f2ac78
AD
242## ----------------------- ##
243## Postprologue syncline. ##
244## ----------------------- ##
642cb8f8 245
06f2ac78 246AT_TEST([Postprologue syncline],
642cb8f8 247[[%{
55f48c48
AD
248]AT_YYERROR_DECLARE_EXTERN[
249]AT_YYLEX_DECLARE_EXTERN[
642cb8f8
AD
250%}
251%union
252{
253 int ival;
254}
255%{
5683e9b2 256#error "10"
642cb8f8
AD
257%}
258%%
259exp: '0';
55f48c48 260%%
642cb8f8 261]],
5683e9b2 262[input.y:10: #error "10"
642cb8f8
AD
263])
264
265
06f2ac78
AD
266## ----------------- ##
267## Action syncline. ##
268## ----------------- ##
642cb8f8 269
06f2ac78 270AT_TEST([Action syncline],
5683e9b2 271[[%{
55f48c48
AD
272]AT_YYERROR_DECLARE_EXTERN[
273]AT_YYLEX_DECLARE_EXTERN[
5683e9b2
AD
274%}
275%%
642cb8f8
AD
276exp:
277{
5683e9b2 278#error "8"
642cb8f8
AD
279};
280]],
5683e9b2 281[input.y:8: #error "8"
642cb8f8
AD
282])
283
284
06f2ac78
AD
285## ------------------- ##
286## Epilogue syncline. ##
287## ------------------- ##
642cb8f8 288
06f2ac78 289AT_TEST([Epilogue syncline],
5683e9b2 290[[%{
55f48c48
AD
291]AT_YYERROR_DECLARE_EXTERN[
292]AT_YYLEX_DECLARE_EXTERN[
5683e9b2
AD
293%}
294%%
642cb8f8
AD
295exp: '0';
296%%
5683e9b2 297#error "8"
642cb8f8 298]],
5683e9b2 299[input.y:8: #error "8"
642cb8f8 300])
1914a781 301
e94ca80b
AD
302## -------------------- ##
303## %code top syncline. ##
304## -------------------- ##
305
306AT_TEST([%code top syncline],
307[[%code top {
308#error "2"
309}
310%{
311]AT_YYERROR_DECLARE_EXTERN[
312]AT_YYLEX_DECLARE_EXTERN[
313%}
314%%
315exp: '0';
316%%
317]],
318[input.y:2: #error "2"
319])
320
321m4_popdef([AT_TEST])
322
323## ----------- ##
324## %no-lines. ##
325## ----------- ##
326
327m4_pushdef([AT_TEST],
781eaf90 328[AT_SETUP([%no-lines: $1])
e94ca80b
AD
329
330AT_BISON_OPTION_PUSHDEFS([%skeleton "$1" %defines])
331AT_DATA_GRAMMAR([input.y],
332[%skeleton "$1" %defines
333%{
334]AT_YYERROR_DECLARE_EXTERN[
335]AT_YYLEX_DECLARE_EXTERN[
336%}
337%%
338exp: '0'
339])
340AT_BISON_CHECK([--no-lines -o input.AT_SKEL_CC_IF([cc], [c]) -d input.y])
341AT_CHECK([[grep '#line' ]AT_SKEL_CC_IF([*.cc *.hh], [*.c *.h])], 1)
342AT_BISON_OPTION_POPDEFS
343
344AT_CLEANUP
345])
346
347AT_TEST([yacc.c])
348AT_TEST([glr.c])
349AT_TEST([lalr1.cc])
350AT_TEST([glr.cc])
351
1914a781 352m4_popdef([AT_TEST])