]> git.saurik.com Git - bison.git/blame - tests/synclines.at
Mention the "yacc" command in the synopsis.
[bison.git] / tests / synclines.at
CommitLineData
642cb8f8 1# Executing Actions. -*- Autotest -*-
1207eeac 2# Copyright (C) 2002 Free Software Foundation, Inc.
642cb8f8
AD
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., 59 Temple Place - Suite 330, Boston, MA
17# 02111-1307, USA.
18
19AT_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
26# (e.g. c89 on IRIX 6.5) triger warnings on `#error', instead of
27# errors.
865b9df1 28m4_define([AT_SYNCLINES_COMPILE],
f32b346d 29[AT_CHECK([$CC $CFLAGS $CPPFLAGS -c $1], [ignore], [], [stderr])
865b9df1
AD
30# In case GCC displays column information, strip it down.
31#
32# input.y:4:2: #error "4" or input.y:4.2: #error "4"
33# =>
34# input.y:4: #error "4"
35#
36AT_CHECK([[sed 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' stderr]], 0, [stdout])
37])
38
642cb8f8
AD
39# AT_TEST_SYNCLINE(TITLE, INPUT, ERROR-MSG)
40# -----------------------------------------
41# Check that compiling the parser produced from INPUT cause GCC
42# to issue ERROR-MSG.
43m4_define([AT_TEST_SYNCLINE],
44[AT_SETUP([$1])
45
865b9df1
AD
46# It seems impossible to find a generic scheme to check the location
47# of an error. Even requiring GCC is not sufficient, since for instance
48# the version modified by Apple:
49#
50# | Reading specs from /usr/libexec/gcc/darwin/ppc/2.95.2/specs
51# | Apple Computer, Inc. version gcc-934.3, based on gcc version 2.95.2
52# | 19991024 (release) configure:2124: $? = 0
53#
54# instead of:
55#
56# | input.y:2: #error "2"
57#
58# it reports:
59#
60# | input.y:2: "2"
61# | cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode
642cb8f8 62
865b9df1
AD
63AT_DATA([syncline.c],
64[[#error "1"
65]])
642cb8f8 66
865b9df1
AD
67AT_SYNCLINES_COMPILE([syncline.c])
68AT_CHECK([[test "`cat stdout`" = 'syncline.c:1: @%:@error "1"' || exit 77]])
69
70AT_DATA([[input.y]], [$2])
b56471a6 71AT_CHECK([bison -o input.c input.y])
865b9df1
AD
72AT_SYNCLINES_COMPILE([input.c])
73AT_CHECK([cat stdout], 0, [$3])
642cb8f8
AD
74AT_CLEANUP
75])
76
77
78## --------------------- ##
79## Prologue synch line. ##
80## --------------------- ##
81
82
83AT_TEST_SYNCLINE([Prologue synch line],
84[[%{
85#error "2"
5683e9b2
AD
86void yyerror (const char *s);
87int yylex (void);
642cb8f8
AD
88%}
89%%
90exp: '0';
91]],
92[input.y:2: #error "2"
93])
94
95
96## ------------------- ##
97## %union synch line. ##
98## ------------------- ##
99
100AT_TEST_SYNCLINE([%union synch line],
101[[%union {
102#error "2"
103}
5683e9b2
AD
104%{
105void yyerror (const char *s);
106int yylex (void);
107%}
642cb8f8
AD
108%%
109exp: '0';
110]],
111[input.y:2: #error "2"
112])
113
114
115## ------------------------- ##
116## Postprologue synch line. ##
117## ------------------------- ##
118
119AT_TEST_SYNCLINE([Postprologue synch line],
120[[%{
5683e9b2
AD
121void yyerror (const char *s);
122int yylex (void);
642cb8f8
AD
123%}
124%union
125{
126 int ival;
127}
128%{
5683e9b2 129#error "10"
642cb8f8
AD
130%}
131%%
132exp: '0';
133]],
5683e9b2 134[input.y:10: #error "10"
642cb8f8
AD
135])
136
137
138## ------------------- ##
139## Action synch line. ##
140## ------------------- ##
141
142AT_TEST_SYNCLINE([Action synch line],
5683e9b2
AD
143[[%{
144void yyerror (const char *s);
145int yylex (void);
146%}
147%%
642cb8f8
AD
148exp:
149{
5683e9b2 150#error "8"
642cb8f8
AD
151};
152]],
5683e9b2 153[input.y:8: #error "8"
642cb8f8
AD
154])
155
156
157## --------------------- ##
158## Epilogue synch line. ##
159## --------------------- ##
160
161AT_TEST_SYNCLINE([Epilogue synch line],
5683e9b2
AD
162[[%{
163void yyerror (const char *s);
164int yylex (void);
165%}
166%%
642cb8f8
AD
167exp: '0';
168%%
5683e9b2 169#error "8"
642cb8f8 170]],
5683e9b2 171[input.y:8: #error "8"
642cb8f8 172])