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