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