]> git.saurik.com Git - bison.git/blame - tests/synclines.at
tests: show a use of %define lr.default-reductions "consistent"
[bison.git] / tests / synclines.at
CommitLineData
642cb8f8 1# Executing Actions. -*- Autotest -*-
401b73af
JD
2# Copyright (C) 2002, 2004, 2005, 2007, 2009 Free Software Foundation,
3# Inc.
642cb8f8 4
f16b0819 5# This program is free software: you can redistribute it and/or modify
642cb8f8 6# it under the terms of the GNU General Public License as published by
f16b0819
PE
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
642cb8f8
AD
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
f16b0819 14#
642cb8f8 15# You should have received a copy of the GNU General Public License
f16b0819 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
642cb8f8
AD
17
18AT_BANNER([[User Actions.]])
19
865b9df1
AD
20
21# AT_SYNCLINES_COMPILE(FILE)
22# --------------------------
4e8d992c
AD
23# Compile FILE expecting an error, and save in the file stdout the
24# normalized output. Ignore the exit status, since some compilers
25# (e.g. c89 on IRIX 6.5) triger warnings on `#error', instead of
26# errors.
865b9df1 27m4_define([AT_SYNCLINES_COMPILE],
f32b346d 28[AT_CHECK([$CC $CFLAGS $CPPFLAGS -c $1], [ignore], [], [stderr])
865b9df1
AD
29# In case GCC displays column information, strip it down.
30#
4d1801f1
PE
31# input.y:4:2: #error "4" or
32# input.y:4.2: #error "4" or
33# input.y:4:2: error: #error "4"
865b9df1
AD
34# =>
35# input.y:4: #error "4"
36#
28169bab
AD
37# It may also issue more context information:
38#
39# input.y: In function 'yyparse':
40# input.y:8: #error "8"
41# =>
42# input.y:4: #error "8"
43#
9142239a
AD
44#
45# And possibly distcc adds its bits.
46#
47# distcc[33187] ERROR: compile (null) on localhost failed
48# syncline.c:1:2: error: #error "1"
49# distcc[33185] ERROR: compile syncline.c on localhost failed
50
51AT_CHECK([[sed -e '/^distcc\[[0-9]*\] ERROR: .*/d' \
52 -e 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' \
28169bab
AD
53 -e 's/^\([^:]*:[^:]*:\)[^@%:@]*\( @%:@error\)/\1\2/' \
54 -e "/^[^:]*: In function '[^\']*':$/d" \
55 stderr]],
56 0, [stdout])
865b9df1
AD
57])
58
642cb8f8
AD
59# AT_TEST_SYNCLINE(TITLE, INPUT, ERROR-MSG)
60# -----------------------------------------
61# Check that compiling the parser produced from INPUT cause GCC
62# to issue ERROR-MSG.
63m4_define([AT_TEST_SYNCLINE],
64[AT_SETUP([$1])
65
865b9df1
AD
66# It seems impossible to find a generic scheme to check the location
67# of an error. Even requiring GCC is not sufficient, since for instance
68# the version modified by Apple:
69#
70# | Reading specs from /usr/libexec/gcc/darwin/ppc/2.95.2/specs
71# | Apple Computer, Inc. version gcc-934.3, based on gcc version 2.95.2
72# | 19991024 (release) configure:2124: $? = 0
73#
74# instead of:
75#
76# | input.y:2: #error "2"
77#
78# it reports:
79#
80# | input.y:2: "2"
81# | cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode
642cb8f8 82
865b9df1
AD
83AT_DATA([syncline.c],
84[[#error "1"
85]])
642cb8f8 86
865b9df1
AD
87AT_SYNCLINES_COMPILE([syncline.c])
88AT_CHECK([[test "`cat stdout`" = 'syncline.c:1: @%:@error "1"' || exit 77]])
89
90AT_DATA([[input.y]], [$2])
da730230 91AT_BISON_CHECK([-o input.c input.y])
865b9df1
AD
92AT_SYNCLINES_COMPILE([input.c])
93AT_CHECK([cat stdout], 0, [$3])
642cb8f8
AD
94AT_CLEANUP
95])
96
97
98## --------------------- ##
99## Prologue synch line. ##
100## --------------------- ##
101
102
103AT_TEST_SYNCLINE([Prologue synch line],
104[[%{
105#error "2"
5683e9b2
AD
106void yyerror (const char *s);
107int yylex (void);
642cb8f8
AD
108%}
109%%
110exp: '0';
111]],
112[input.y:2: #error "2"
113])
114
115
116## ------------------- ##
117## %union synch line. ##
118## ------------------- ##
119
120AT_TEST_SYNCLINE([%union synch line],
121[[%union {
122#error "2"
0f53f222 123 char dummy;
642cb8f8 124}
5683e9b2
AD
125%{
126void yyerror (const char *s);
127int yylex (void);
128%}
642cb8f8
AD
129%%
130exp: '0';
131]],
132[input.y:2: #error "2"
133])
134
135
136## ------------------------- ##
137## Postprologue synch line. ##
138## ------------------------- ##
139
140AT_TEST_SYNCLINE([Postprologue synch line],
141[[%{
5683e9b2
AD
142void yyerror (const char *s);
143int yylex (void);
642cb8f8
AD
144%}
145%union
146{
147 int ival;
148}
149%{
5683e9b2 150#error "10"
642cb8f8
AD
151%}
152%%
153exp: '0';
154]],
5683e9b2 155[input.y:10: #error "10"
642cb8f8
AD
156])
157
158
159## ------------------- ##
160## Action synch line. ##
161## ------------------- ##
162
163AT_TEST_SYNCLINE([Action synch line],
5683e9b2
AD
164[[%{
165void yyerror (const char *s);
166int yylex (void);
167%}
168%%
642cb8f8
AD
169exp:
170{
5683e9b2 171#error "8"
642cb8f8
AD
172};
173]],
5683e9b2 174[input.y:8: #error "8"
642cb8f8
AD
175])
176
177
178## --------------------- ##
179## Epilogue synch line. ##
180## --------------------- ##
181
182AT_TEST_SYNCLINE([Epilogue synch line],
5683e9b2
AD
183[[%{
184void yyerror (const char *s);
185int yylex (void);
186%}
187%%
642cb8f8
AD
188exp: '0';
189%%
5683e9b2 190#error "8"
642cb8f8 191]],
5683e9b2 192[input.y:8: #error "8"
642cb8f8 193])