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