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