]> git.saurik.com Git - bison.git/blob - tests/synclines.at
* tests/testsuite.at (AT_CHECK): When checking if $1 starts with
[bison.git] / tests / synclines.at
1 # Executing Actions. -*- Autotest -*-
2 # Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
7 # any later version.
8
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.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 # 02110-1301, USA.
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) triger 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 AT_CHECK([[sed -e 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' -e 's/^\([^:]*:[^:]*:\)[^@%:@]*\( @%:@error\)/\1\2/' stderr]], 0, [stdout])
39 ])
40
41 # AT_TEST_SYNCLINE(TITLE, INPUT, ERROR-MSG)
42 # -----------------------------------------
43 # Check that compiling the parser produced from INPUT cause GCC
44 # to issue ERROR-MSG.
45 m4_define([AT_TEST_SYNCLINE],
46 [AT_SETUP([$1])
47
48 # It seems impossible to find a generic scheme to check the location
49 # of an error. Even requiring GCC is not sufficient, since for instance
50 # the version modified by Apple:
51 #
52 # | Reading specs from /usr/libexec/gcc/darwin/ppc/2.95.2/specs
53 # | Apple Computer, Inc. version gcc-934.3, based on gcc version 2.95.2
54 # | 19991024 (release) configure:2124: $? = 0
55 #
56 # instead of:
57 #
58 # | input.y:2: #error "2"
59 #
60 # it reports:
61 #
62 # | input.y:2: "2"
63 # | cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode
64
65 AT_DATA([syncline.c],
66 [[#error "1"
67 ]])
68
69 AT_SYNCLINES_COMPILE([syncline.c])
70 AT_CHECK([[test "`cat stdout`" = 'syncline.c:1: @%:@error "1"' || exit 77]])
71
72 AT_DATA([[input.y]], [$2])
73 AT_CHECK([bison -o input.c input.y])
74 AT_SYNCLINES_COMPILE([input.c])
75 AT_CHECK([cat stdout], 0, [$3])
76 AT_CLEANUP
77 ])
78
79
80 ## --------------------- ##
81 ## Prologue synch line. ##
82 ## --------------------- ##
83
84
85 AT_TEST_SYNCLINE([Prologue synch line],
86 [[%{
87 #error "2"
88 void yyerror (const char *s);
89 int yylex (void);
90 %}
91 %%
92 exp: '0';
93 ]],
94 [input.y:2: #error "2"
95 ])
96
97
98 ## ------------------- ##
99 ## %union synch line. ##
100 ## ------------------- ##
101
102 AT_TEST_SYNCLINE([%union synch line],
103 [[%union {
104 #error "2"
105 char dummy;
106 }
107 %{
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 ## Postprologue synch line. ##
120 ## ------------------------- ##
121
122 AT_TEST_SYNCLINE([Postprologue synch line],
123 [[%{
124 void yyerror (const char *s);
125 int yylex (void);
126 %}
127 %union
128 {
129 int ival;
130 }
131 %{
132 #error "10"
133 %}
134 %%
135 exp: '0';
136 ]],
137 [input.y:10: #error "10"
138 ])
139
140
141 ## ------------------- ##
142 ## Action synch line. ##
143 ## ------------------- ##
144
145 AT_TEST_SYNCLINE([Action synch line],
146 [[%{
147 void yyerror (const char *s);
148 int yylex (void);
149 %}
150 %%
151 exp:
152 {
153 #error "8"
154 };
155 ]],
156 [input.y:8: #error "8"
157 ])
158
159
160 ## --------------------- ##
161 ## Epilogue synch line. ##
162 ## --------------------- ##
163
164 AT_TEST_SYNCLINE([Epilogue synch line],
165 [[%{
166 void yyerror (const char *s);
167 int yylex (void);
168 %}
169 %%
170 exp: '0';
171 %%
172 #error "8"
173 ]],
174 [input.y:8: #error "8"
175 ])