]> git.saurik.com Git - bison.git/blame_incremental - tests/synclines.at
doc: minor fixes
[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
79AT_CHECK([[$PERL -p -0777 - stderr <<\EOF
80 # 1. Remove useless lines.
81
82 # distcc clutter.
83 s/^distcc\[\d+\] .*\n//gm;
84 # c vs. c++.
85 s/^clang: warning: treating 'c' input as 'c\+\+'.*\n//gm;
86 # Function context.
87 s/^[^:]*: In function '[^']+':\n//gm;
88 # Caret error.
89 s/^ *#error.*\n *\^\n//gm;
90 # Number of errors.
91 s/^1 error generated\.\n//gm;
92
93 # 2. Normalize the lines we kept.
94
95 # Remove column.
96 s/^([^:]+:\d+)[.:][^:]+:(.+)$/$][1:$][2/gm;
97 # Map all combinations of "error: " and "#error: " to "#error ".
98 s/^([^:]+:\d+):( |#error|error|:)+/$][1: #error /gm;
99EOF
100]],
101 0, [stdout])
102])
103
104# AT_TEST(TITLE, INPUT, ERROR-MSG)
105# --------------------------------
106# Check that compiling the parser produced from INPUT cause GCC
107# to issue ERROR-MSG.
108m4_pushdef([AT_TEST],
109[AT_SETUP([$1])
110AT_BISON_OPTION_PUSHDEFS
111# It seems impossible to find a generic scheme to check the location
112# of an error. Even requiring GCC is not sufficient, since for instance
113# the version modified by Apple:
114#
115# | Reading specs from /usr/libexec/gcc/darwin/ppc/2.95.2/specs
116# | Apple Computer, Inc. version gcc-934.3, based on gcc version 2.95.2
117# | 19991024 (release) configure:2124: $? = 0
118#
119# instead of:
120#
121# | input.y:2: #error "2"
122#
123# it reports:
124#
125# | input.y:2: "2"
126# | cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode
127
128AT_DATA([syncline.c],
129[[#error "1"
130int i; /* avoids -pedantic warning about an empty translation unit. */
131]])
132
133AT_SYNCLINES_COMPILE([syncline.c])
134AT_CHECK([[test "`cat stdout`" = 'syncline.c:1: @%:@error "1"' || exit 77]])
135
136AT_DATA([[input.y]], [$2])
137AT_BISON_CHECK([-o input.c input.y])
138AT_SYNCLINES_COMPILE([input.c])
139AT_CHECK([cat stdout], 0, [$3])
140AT_BISON_OPTION_POPDEFS
141AT_CLEANUP
142])
143
144
145## ------------------- ##
146## Prologue syncline. ##
147## ------------------- ##
148
149
150AT_TEST([Prologue syncline],
151[[%{
152#error "2"
153]AT_YYERROR_DECLARE_EXTERN[
154]AT_YYLEX_DECLARE_EXTERN[
155%}
156%%
157exp: '0';
158%%
159]],
160[input.y:2: #error "2"
161])
162
163
164## ----------------- ##
165## %union syncline. ##
166## ----------------- ##
167
168AT_TEST([%union syncline],
169[[%union {
170#error "2"
171 char dummy;
172}
173%{
174]AT_YYERROR_DECLARE_EXTERN[
175]AT_YYLEX_DECLARE_EXTERN[
176%}
177%%
178exp: '0';
179%%
180]],
181[input.y:2: #error "2"
182])
183
184
185## ---------------------- ##
186## %union name syncline. ##
187## ---------------------- ##
188
189# Check that invalid union names are properly reported in the
190# source file.
191AT_SETUP([%union name syncline])
192AT_BISON_OPTION_PUSHDEFS
193AT_DATA([[input.y]],
194[[%union break
195{
196 char dummy;
197}
198%{
199]AT_YYERROR_DECLARE_EXTERN[
200]AT_YYLEX_DECLARE_EXTERN[
201%}
202%%
203exp: '0';
204%%
205]])
206
207AT_BISON_CHECK([-o input.c input.y])
208AT_SYNCLINES_COMPILE([input.c])
209AT_CHECK([[grep '^input.y:1' stdout]], 0, [ignore])
210AT_BISON_OPTION_POPDEFS
211AT_CLEANUP
212
213
214## ----------------------- ##
215## Postprologue syncline. ##
216## ----------------------- ##
217
218AT_TEST([Postprologue syncline],
219[[%{
220]AT_YYERROR_DECLARE_EXTERN[
221]AT_YYLEX_DECLARE_EXTERN[
222%}
223%union
224{
225 int ival;
226}
227%{
228#error "10"
229%}
230%%
231exp: '0';
232%%
233]],
234[input.y:10: #error "10"
235])
236
237
238## ----------------- ##
239## Action syncline. ##
240## ----------------- ##
241
242AT_TEST([Action syncline],
243[[%{
244]AT_YYERROR_DECLARE_EXTERN[
245]AT_YYLEX_DECLARE_EXTERN[
246%}
247%%
248exp:
249{
250#error "8"
251};
252]],
253[input.y:8: #error "8"
254])
255
256
257## ------------------- ##
258## Epilogue syncline. ##
259## ------------------- ##
260
261AT_TEST([Epilogue syncline],
262[[%{
263]AT_YYERROR_DECLARE_EXTERN[
264]AT_YYLEX_DECLARE_EXTERN[
265%}
266%%
267exp: '0';
268%%
269#error "8"
270]],
271[input.y:8: #error "8"
272])
273
274## -------------------- ##
275## %code top syncline. ##
276## -------------------- ##
277
278AT_TEST([%code top syncline],
279[[%code top {
280#error "2"
281}
282%{
283]AT_YYERROR_DECLARE_EXTERN[
284]AT_YYLEX_DECLARE_EXTERN[
285%}
286%%
287exp: '0';
288%%
289]],
290[input.y:2: #error "2"
291])
292
293m4_popdef([AT_TEST])
294
295## ----------- ##
296## %no-lines. ##
297## ----------- ##
298
299m4_pushdef([AT_TEST],
300[AT_SETUP([%no-lines: $1])
301
302AT_BISON_OPTION_PUSHDEFS([%skeleton "$1" %defines])
303AT_DATA_GRAMMAR([input.y],
304[%skeleton "$1" %defines
305%{
306]AT_YYERROR_DECLARE_EXTERN[
307]AT_YYLEX_DECLARE_EXTERN[
308%}
309%%
310exp: '0'
311])
312AT_BISON_CHECK([--no-lines -o input.AT_SKEL_CC_IF([cc], [c]) -d input.y])
313AT_CHECK([[grep '#line' ]AT_SKEL_CC_IF([*.cc *.hh], [*.c *.h])], 1)
314AT_BISON_OPTION_POPDEFS
315
316AT_CLEANUP
317])
318
319AT_TEST([yacc.c])
320AT_TEST([glr.c])
321AT_TEST([lalr1.cc])
322AT_TEST([glr.cc])
323
324m4_popdef([AT_TEST])