]> git.saurik.com Git - bison.git/blob - tests/synclines.at
test location_type.
[bison.git] / tests / synclines.at
1 # Executing Actions. -*- Autotest -*-
2 # Copyright (C) 2002, 2004-2005, 2007, 2009-2010 Free Software
3 # Foundation, Inc.
4
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
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.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 AT_BANNER([[User Actions.]])
19
20
21 # AT_SYNCLINES_COMPILE(FILE)
22 # --------------------------
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.
27 m4_define([AT_SYNCLINES_COMPILE],
28 [AT_CHECK([$CC $CFLAGS $CPPFLAGS -c $1], [ignore], [], [stderr])
29 # In case GCC displays column information, strip it down.
30 #
31 # input.y:4:2: #error "4" or
32 # input.y:4.2: #error "4" or
33 # input.y:4:2: error: #error "4"
34 # =>
35 # input.y:4: #error "4"
36 #
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 #
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
51 AT_CHECK([[sed -e '/^distcc\[[0-9]*\] ERROR: .*/d' \
52 -e 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' \
53 -e 's/^\([^:]*:[^:]*:\)[^@%:@]*\( @%:@error\)/\1\2/' \
54 -e "/^[^:]*: In function '[^\']*':$/d" \
55 stderr]],
56 0, [stdout])
57 ])
58
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.
63 m4_define([AT_TEST_SYNCLINE],
64 [AT_SETUP([$1])
65
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
82
83 AT_DATA([syncline.c],
84 [[#error "1"
85 ]])
86
87 AT_SYNCLINES_COMPILE([syncline.c])
88 AT_CHECK([[test "`cat stdout`" = 'syncline.c:1: @%:@error "1"' || exit 77]])
89
90 AT_DATA([[input.y]], [$2])
91 AT_BISON_CHECK([-o input.c input.y])
92 AT_SYNCLINES_COMPILE([input.c])
93 # GCC 4.5 tells you the function within which #error appears, but
94 # previous versions of gcc do not.
95 AT_CHECK([grep -v ': In function ' stdout], 0, [$3])
96 AT_CLEANUP
97 ])
98
99
100 ## --------------------- ##
101 ## Prologue synch line. ##
102 ## --------------------- ##
103
104
105 AT_TEST_SYNCLINE([Prologue synch line],
106 [[%{
107 #error "2"
108 void yyerror (const char *s);
109 int yylex (void);
110 %}
111 %%
112 exp: '0';
113 ]],
114 [input.y:2: #error "2"
115 ])
116
117
118 ## ------------------- ##
119 ## %union synch line. ##
120 ## ------------------- ##
121
122 AT_TEST_SYNCLINE([%union synch line],
123 [[%union {
124 #error "2"
125 char dummy;
126 }
127 %{
128 void yyerror (const char *s);
129 int yylex (void);
130 %}
131 %%
132 exp: '0';
133 ]],
134 [input.y:2: #error "2"
135 ])
136
137
138 ## ------------------------- ##
139 ## Postprologue synch line. ##
140 ## ------------------------- ##
141
142 AT_TEST_SYNCLINE([Postprologue synch line],
143 [[%{
144 void yyerror (const char *s);
145 int yylex (void);
146 %}
147 %union
148 {
149 int ival;
150 }
151 %{
152 #error "10"
153 %}
154 %%
155 exp: '0';
156 ]],
157 [input.y:10: #error "10"
158 ])
159
160
161 ## ------------------- ##
162 ## Action synch line. ##
163 ## ------------------- ##
164
165 AT_TEST_SYNCLINE([Action synch line],
166 [[%{
167 void yyerror (const char *s);
168 int yylex (void);
169 %}
170 %%
171 exp:
172 {
173 #error "8"
174 };
175 ]],
176 [input.y:8: #error "8"
177 ])
178
179
180 ## --------------------- ##
181 ## Epilogue synch line. ##
182 ## --------------------- ##
183
184 AT_TEST_SYNCLINE([Epilogue synch line],
185 [[%{
186 void yyerror (const char *s);
187 int yylex (void);
188 %}
189 %%
190 exp: '0';
191 %%
192 #error "8"
193 ]],
194 [input.y:8: #error "8"
195 ])