]> git.saurik.com Git - bison.git/blame - tests/synclines.at
tests: GCC 4.5 compliance.
[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#
44AT_CHECK([[sed -e 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' \
45 -e 's/^\([^:]*:[^:]*:\)[^@%:@]*\( @%:@error\)/\1\2/' \
46 -e "/^[^:]*: In function '[^\']*':$/d" \
47 stderr]],
48 0, [stdout])
865b9df1
AD
49])
50
642cb8f8
AD
51# AT_TEST_SYNCLINE(TITLE, INPUT, ERROR-MSG)
52# -----------------------------------------
53# Check that compiling the parser produced from INPUT cause GCC
54# to issue ERROR-MSG.
55m4_define([AT_TEST_SYNCLINE],
56[AT_SETUP([$1])
57
865b9df1
AD
58# It seems impossible to find a generic scheme to check the location
59# of an error. Even requiring GCC is not sufficient, since for instance
60# the version modified by Apple:
61#
62# | Reading specs from /usr/libexec/gcc/darwin/ppc/2.95.2/specs
63# | Apple Computer, Inc. version gcc-934.3, based on gcc version 2.95.2
64# | 19991024 (release) configure:2124: $? = 0
65#
66# instead of:
67#
68# | input.y:2: #error "2"
69#
70# it reports:
71#
72# | input.y:2: "2"
73# | cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode
642cb8f8 74
865b9df1
AD
75AT_DATA([syncline.c],
76[[#error "1"
77]])
642cb8f8 78
865b9df1
AD
79AT_SYNCLINES_COMPILE([syncline.c])
80AT_CHECK([[test "`cat stdout`" = 'syncline.c:1: @%:@error "1"' || exit 77]])
81
82AT_DATA([[input.y]], [$2])
da730230 83AT_BISON_CHECK([-o input.c input.y])
865b9df1
AD
84AT_SYNCLINES_COMPILE([input.c])
85AT_CHECK([cat stdout], 0, [$3])
642cb8f8
AD
86AT_CLEANUP
87])
88
89
90## --------------------- ##
91## Prologue synch line. ##
92## --------------------- ##
93
94
95AT_TEST_SYNCLINE([Prologue synch line],
96[[%{
97#error "2"
5683e9b2
AD
98void yyerror (const char *s);
99int yylex (void);
642cb8f8
AD
100%}
101%%
102exp: '0';
103]],
104[input.y:2: #error "2"
105])
106
107
108## ------------------- ##
109## %union synch line. ##
110## ------------------- ##
111
112AT_TEST_SYNCLINE([%union synch line],
113[[%union {
114#error "2"
0f53f222 115 char dummy;
642cb8f8 116}
5683e9b2
AD
117%{
118void yyerror (const char *s);
119int yylex (void);
120%}
642cb8f8
AD
121%%
122exp: '0';
123]],
124[input.y:2: #error "2"
125])
126
127
128## ------------------------- ##
129## Postprologue synch line. ##
130## ------------------------- ##
131
132AT_TEST_SYNCLINE([Postprologue synch line],
133[[%{
5683e9b2
AD
134void yyerror (const char *s);
135int yylex (void);
642cb8f8
AD
136%}
137%union
138{
139 int ival;
140}
141%{
5683e9b2 142#error "10"
642cb8f8
AD
143%}
144%%
145exp: '0';
146]],
5683e9b2 147[input.y:10: #error "10"
642cb8f8
AD
148])
149
150
151## ------------------- ##
152## Action synch line. ##
153## ------------------- ##
154
155AT_TEST_SYNCLINE([Action synch line],
5683e9b2
AD
156[[%{
157void yyerror (const char *s);
158int yylex (void);
159%}
160%%
642cb8f8
AD
161exp:
162{
5683e9b2 163#error "8"
642cb8f8
AD
164};
165]],
5683e9b2 166[input.y:8: #error "8"
642cb8f8
AD
167])
168
169
170## --------------------- ##
171## Epilogue synch line. ##
172## --------------------- ##
173
174AT_TEST_SYNCLINE([Epilogue synch line],
5683e9b2
AD
175[[%{
176void yyerror (const char *s);
177int yylex (void);
178%}
179%%
642cb8f8
AD
180exp: '0';
181%%
5683e9b2 182#error "8"
642cb8f8 183]],
5683e9b2 184[input.y:8: #error "8"
642cb8f8 185])