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