]> 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
c932d613 3# Copyright (C) 2002, 2004-2005, 2007, 2009-2012 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
AD
21
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
bdc360ae 26# (e.g. c89 on IRIX 6.5) trigger warnings on `#error', instead of
4e8d992c 27# errors.
865b9df1 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#
0bb672d8
AD
50# The message may include a caret-error:
51#
52# input.y:1:2: error: #error "1"
53# #error "1"
54# ^
bdc360ae
AD
55#
56# And possibly distcc adds its bits.
57#
58# distcc[33187] ERROR: compile (null) on localhost failed
59# syncline.c:1:2: error: #error "1"
60# distcc[33185] ERROR: compile syncline.c on localhost failed
61#
62# or even
63#
64# distcc[35882] (dcc_connect_by_name) ERROR: failed to look up host "chrisimac": Unknown host
65# distcc[35882] Warning: failed to distribute input.c to chrisimac/4, running locally instead
66
c955769a 67AT_CHECK([[$PERL -p -0777 - stderr <<\EOF
1914a781
AD
68 s/^distcc\[\d+\] .*\n//gm;
69 s/^([^:]+:\d+)[.:][^:]+:(.+)$/$][1:$][2/gm;
70 s/^([^:]+:\d+):[^#]*( #error)/$][1:$][2/gm;
71 s/^[^:]*: In function '[^']+':\n//gm;
72 s/^\ +#error.*\n\ *\^\n//gm;
0bb672d8
AD
73EOF
74]],
1914a781 75 0, [stdout])
865b9df1
AD
76])
77
1914a781
AD
78# AT_TEST(TITLE, INPUT, ERROR-MSG)
79# --------------------------------
642cb8f8
AD
80# Check that compiling the parser produced from INPUT cause GCC
81# to issue ERROR-MSG.
1914a781 82m4_pushdef([AT_TEST],
642cb8f8 83[AT_SETUP([$1])
55f48c48 84AT_BISON_OPTION_PUSHDEFS
865b9df1
AD
85# It seems impossible to find a generic scheme to check the location
86# of an error. Even requiring GCC is not sufficient, since for instance
87# the version modified by Apple:
88#
89# | Reading specs from /usr/libexec/gcc/darwin/ppc/2.95.2/specs
90# | Apple Computer, Inc. version gcc-934.3, based on gcc version 2.95.2
91# | 19991024 (release) configure:2124: $? = 0
92#
93# instead of:
94#
95# | input.y:2: #error "2"
96#
97# it reports:
98#
99# | input.y:2: "2"
100# | cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode
642cb8f8 101
865b9df1
AD
102AT_DATA([syncline.c],
103[[#error "1"
5422d56a 104int i; // avoids -pedantic warning about an empty translation unit
865b9df1 105]])
642cb8f8 106
865b9df1
AD
107AT_SYNCLINES_COMPILE([syncline.c])
108AT_CHECK([[test "`cat stdout`" = 'syncline.c:1: @%:@error "1"' || exit 77]])
109
110AT_DATA([[input.y]], [$2])
da730230 111AT_BISON_CHECK([-o input.c input.y])
865b9df1 112AT_SYNCLINES_COMPILE([input.c])
bdc360ae 113AT_CHECK([cat stdout], 0, [$3])
55f48c48 114AT_BISON_OPTION_POPDEFS
642cb8f8
AD
115AT_CLEANUP
116])
117
118
06f2ac78
AD
119## ------------------- ##
120## Prologue syncline. ##
121## ------------------- ##
642cb8f8
AD
122
123
06f2ac78 124AT_TEST([Prologue syncline],
642cb8f8
AD
125[[%{
126#error "2"
55f48c48
AD
127]AT_YYERROR_DECLARE_EXTERN[
128]AT_YYLEX_DECLARE_EXTERN[
642cb8f8
AD
129%}
130%%
131exp: '0';
55f48c48 132%%
642cb8f8
AD
133]],
134[input.y:2: #error "2"
135])
136
137
06f2ac78
AD
138## ----------------- ##
139## %union syncline. ##
140## ----------------- ##
642cb8f8 141
06f2ac78 142AT_TEST([%union syncline],
642cb8f8
AD
143[[%union {
144#error "2"
0f53f222 145 char dummy;
642cb8f8 146}
5683e9b2 147%{
55f48c48
AD
148]AT_YYERROR_DECLARE_EXTERN[
149]AT_YYLEX_DECLARE_EXTERN[
5683e9b2 150%}
642cb8f8
AD
151%%
152exp: '0';
55f48c48 153%%
642cb8f8
AD
154]],
155[input.y:2: #error "2"
156])
157
158
06f2ac78
AD
159## ----------------------- ##
160## Postprologue syncline. ##
161## ----------------------- ##
642cb8f8 162
06f2ac78 163AT_TEST([Postprologue syncline],
642cb8f8 164[[%{
55f48c48
AD
165]AT_YYERROR_DECLARE_EXTERN[
166]AT_YYLEX_DECLARE_EXTERN[
642cb8f8
AD
167%}
168%union
169{
170 int ival;
171}
172%{
5683e9b2 173#error "10"
642cb8f8
AD
174%}
175%%
176exp: '0';
55f48c48 177%%
642cb8f8 178]],
5683e9b2 179[input.y:10: #error "10"
642cb8f8
AD
180])
181
182
06f2ac78
AD
183## ----------------- ##
184## Action syncline. ##
185## ----------------- ##
642cb8f8 186
06f2ac78 187AT_TEST([Action syncline],
5683e9b2 188[[%{
55f48c48
AD
189]AT_YYERROR_DECLARE_EXTERN[
190]AT_YYLEX_DECLARE_EXTERN[
5683e9b2
AD
191%}
192%%
642cb8f8
AD
193exp:
194{
5683e9b2 195#error "8"
642cb8f8
AD
196};
197]],
5683e9b2 198[input.y:8: #error "8"
642cb8f8
AD
199])
200
201
06f2ac78
AD
202## ------------------- ##
203## Epilogue syncline. ##
204## ------------------- ##
642cb8f8 205
06f2ac78 206AT_TEST([Epilogue syncline],
5683e9b2 207[[%{
55f48c48
AD
208]AT_YYERROR_DECLARE_EXTERN[
209]AT_YYLEX_DECLARE_EXTERN[
5683e9b2
AD
210%}
211%%
642cb8f8
AD
212exp: '0';
213%%
5683e9b2 214#error "8"
642cb8f8 215]],
5683e9b2 216[input.y:8: #error "8"
642cb8f8 217])
1914a781 218
ae219938
AD
219## -------------------- ##
220## %code top syncline. ##
221## -------------------- ##
222
223AT_TEST([%code top syncline],
224[[%code top {
225#error "2"
226}
227%{
228]AT_YYERROR_DECLARE_EXTERN[
229]AT_YYLEX_DECLARE_EXTERN[
230%}
231%%
232exp: '0';
233%%
234]],
235[input.y:2: #error "2"
236])
237
238m4_popdef([AT_TEST])
239
240## ----------- ##
241## %no-lines. ##
242## ----------- ##
243
244m4_pushdef([AT_TEST],
245[AT_SETUP([%no-lines])
246
247AT_BISON_OPTION_PUSHDEFS([%skeleton "$1" %defines])
248AT_DATA_GRAMMAR([input.y],
249[%skeleton "$1" %defines
250%{
251]AT_YYERROR_DECLARE_EXTERN[
252]AT_YYLEX_DECLARE_EXTERN[
253%}
254%%
255exp: '0'
256])
257AT_BISON_CHECK([--no-lines -o input.AT_SKEL_CC_IF([cc], [c]) -d input.y])
258AT_CHECK([[grep '#line' ]AT_SKEL_CC_IF([*.cc *.hh], [*.c *.h])], 1)
259AT_BISON_OPTION_POPDEFS
260
261AT_CLEANUP
262])
263
264AT_TEST([yacc.c])
265AT_TEST([glr.c])
266AT_TEST([lalr1.cc])
267AT_TEST([glr.cc])
268
1914a781 269m4_popdef([AT_TEST])