]> git.saurik.com Git - bison.git/blame - tests/output.at
headers: move CPP guards into YY_*_INCLUDED to avoid collisions
[bison.git] / tests / output.at
CommitLineData
342b8b6e 1# Checking the output filenames. -*- Autotest -*-
6e30ede8 2
c932d613 3# Copyright (C) 2000-2002, 2005-2012 Free Software Foundation, Inc.
342b8b6e 4
f16b0819 5# This program is free software: you can redistribute it and/or modify
342b8b6e 6# it under the terms of the GNU General Public License as published by
f16b0819
PE
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
342b8b6e
AD
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.
f16b0819 14#
342b8b6e 15# You should have received a copy of the GNU General Public License
f16b0819 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
342b8b6e
AD
17
18AT_BANNER([[Output file names.]])
19
20
7625ec2c 21# AT_CHECK_OUTPUT(INPUT-FILE, [DIRECTIVES], [FLAGS], EXPECTED-FILES, [SHELLIO],
0162a44c 22# [ADDITIONAL-TESTS], [PRE-TESTS])
f1bbfcce 23# -----------------------------------------------------------------------------
342b8b6e 24m4_define([AT_CHECK_OUTPUT],
bd9d212b 25[AT_SETUP([[Output files: $2 $3 $5]])
0162a44c 26$7
cae5057f
JD
27for file in $1 $4; do
28 case "$file" in
29 */*) mkdir -p `echo "$file" | sed 's,/.*,,'`;;
30 esac
31done
342b8b6e
AD
32AT_DATA([$1],
33[[$2
34%%
bfcf1f3a 35foo: {};
342b8b6e
AD
36]])
37
da730230 38AT_BISON_CHECK([$3 $1 $5], 0)
342b8b6e 39AT_CHECK([ls $4], [], [ignore])
7625ec2c 40$6
d803322e 41AT_CLEANUP
342b8b6e
AD
42])
43
44AT_CHECK_OUTPUT([foo.y], [], [-dv],
02650b7f 45 [foo.output foo.tab.c foo.tab.h])
0162a44c
JD
46
47# Some versions of Valgrind (at least valgrind-3.6.0.SVN-Debian) report
48# "fgrep: write error: Bad file descriptor" when stdout is closed, so we
49# skip this test group during maintainer-check-valgrind.
f1bbfcce 50AT_CHECK_OUTPUT([foo.y], [], [-dv],
02650b7f 51 [foo.output foo.tab.c foo.tab.h],
0162a44c
JD
52 [>&-], [],
53 [AT_CHECK([[case "$PREBISON" in *valgrind*) exit 77;; esac]])])
54
342b8b6e 55AT_CHECK_OUTPUT([foo.y], [], [-dv -o foo.c],
02650b7f 56 [foo.c foo.h foo.output])
342b8b6e 57AT_CHECK_OUTPUT([foo.y], [], [-dv -o foo.tab.c],
02650b7f 58 [foo.output foo.tab.c foo.tab.h])
342b8b6e 59AT_CHECK_OUTPUT([foo.y], [], [-dv -y],
02650b7f 60 [y.output y.tab.c y.tab.h])
342b8b6e 61AT_CHECK_OUTPUT([foo.y], [], [-dv -b bar],
02650b7f 62 [bar.output bar.tab.c bar.tab.h])
342b8b6e 63AT_CHECK_OUTPUT([foo.y], [], [-dv -g -o foo.c],
35fe0834 64 [foo.c foo.dot foo.h foo.output])
342b8b6e
AD
65
66
67AT_CHECK_OUTPUT([foo.y], [%defines %verbose], [],
02650b7f 68 [foo.output foo.tab.c foo.tab.h])
342b8b6e 69AT_CHECK_OUTPUT([foo.y], [%defines %verbose %yacc],[],
02650b7f 70 [y.output y.tab.c y.tab.h])
342b8b6e 71
5e5d5415 72AT_CHECK_OUTPUT([foo.yy], [%defines %verbose %yacc],[],
02650b7f 73 [y.output y.tab.c y.tab.h])
5e5d5415 74
9874f80b 75# Exercise %output and %file-prefix including deprecated '='
02975b9a 76AT_CHECK_OUTPUT([foo.y], [%file-prefix "bar" %defines %verbose], [],
02650b7f 77 [bar.output bar.tab.c bar.tab.h])
951366c1 78AT_CHECK_OUTPUT([foo.y], [%output="bar.c" %defines %verbose %yacc],[],
02650b7f 79 [bar.output bar.c bar.h])
951366c1 80AT_CHECK_OUTPUT([foo.y],
02975b9a 81 [%file-prefix="baz" %output "bar.c" %defines %verbose %yacc],
02650b7f
PE
82 [],
83 [bar.output bar.c bar.h])
951366c1 84
342b8b6e
AD
85
86# Check priorities of extension control.
87AT_CHECK_OUTPUT([foo.yy], [%defines %verbose], [],
02650b7f 88 [foo.output foo.tab.cc foo.tab.hh])
342b8b6e
AD
89
90AT_CHECK_OUTPUT([foo.yy], [%defines %verbose ], [-o foo.c],
02650b7f 91 [foo.c foo.h foo.output])
342b8b6e
AD
92
93AT_CHECK_OUTPUT([foo.yy], [],
02650b7f
PE
94 [--defines=foo.hpp -o foo.c++],
95 [foo.c++ foo.hpp])
342b8b6e 96
02975b9a
JD
97AT_CHECK_OUTPUT([foo.yy], [%defines "foo.hpp"],
98 [-o foo.c++],
99 [foo.c++ foo.hpp])
100
342b8b6e 101AT_CHECK_OUTPUT([foo.yy], [],
02650b7f
PE
102 [-o foo.c++ --graph=foo.gph],
103 [foo.c++ foo.gph])
7625ec2c
AD
104
105
106## ------------ ##
107## C++ output. ##
108## ------------ ##
109
110m4_define([AT_CHECK_NO_SUBDIR_PART],
111[# Also make sure that the includes do not refer to the subdirectory.
112AT_CHECK([grep 'include .subdir/' $1.cc], 1, [])
113AT_CHECK([grep 'include .subdir/' $1.hh], 1, [])
114])
115
116AT_CHECK_OUTPUT([foo.yy], [%skeleton "lalr1.cc" %defines %verbose], [],
02650b7f 117 [foo.tab.cc foo.tab.hh foo.output location.hh stack.hh position.hh])
7625ec2c
AD
118
119AT_CHECK_OUTPUT([subdir/foo.yy], [%skeleton "lalr1.cc" %defines %verbose], [],
02650b7f
PE
120 [foo.tab.cc foo.tab.hh foo.output location.hh stack.hh position.hh],
121 [], [AT_CHECK_NO_SUBDIR_PART([foo.tab])])
7625ec2c
AD
122
123AT_CHECK_OUTPUT([subdir/foo.yy], [%skeleton "lalr1.cc" %defines %verbose],
124 [-o subdir/foo.cc],
02650b7f 125 [subdir/foo.cc subdir/foo.hh subdir/foo.output subdir/location.hh subdir/stack.hh subdir/position.hh],
7625ec2c 126 [], [AT_CHECK_NO_SUBDIR_PART([subdir/foo])])
3f7ca628 127
cae5057f
JD
128AT_CHECK_OUTPUT([gram_dir/foo.yy],
129 [%skeleton "lalr1.cc" %defines %verbose %file-prefix "output_dir/foo"],
130 [],
131 [output_dir/foo.tab.cc output_dir/foo.tab.hh output_dir/foo.output output_dir/location.hh output_dir/stack.hh output_dir/position.hh])
132
3f7ca628 133
c0ee9e21
DJ
134# AT_CHECK_CONFLICTING_OUTPUT(INPUT-FILE, DIRECTIVES, FLAGS, STDERR,
135# [EXIT-STATUS])
136# ------------------------------------------------------------------
3f7ca628
JD
137m4_define([AT_CHECK_CONFLICTING_OUTPUT],
138[AT_SETUP([Conflicting output files: $2 $3])
139case "$1" in
140 */*) mkdir `echo "$1" | sed 's,/.*,,'`;;
141esac
142AT_DATA([$1],
143[[$2
144%%
145foo: {};
146]])
147
47fa5747 148[cp ]$1[ expout]
c50befe6
JD
149# Because an output file name conflict is still a warning, Bison exits
150# with status 0, so AT_BISON_CHECK does not realize that there may be no
151# output file against which to check the XML. AT_BISON_CHECK_NO_XML
152# avoids that problem.
153AT_BISON_CHECK_NO_XML([$3 $1], $5, [], [$4])
47fa5747 154AT_CHECK([[cat $1]], [[0]], [expout])
3f7ca628
JD
155AT_CLEANUP
156])
157
158AT_CHECK_CONFLICTING_OUTPUT([foo.y],
159[], [--graph="foo.tab.c"],
9874f80b 160[foo.y: warning: conflicting outputs to file 'foo.tab.c'
3f7ca628
JD
161])
162
163AT_CHECK_CONFLICTING_OUTPUT([foo.y],
164[%defines "foo.output"], [-v],
9874f80b 165[foo.y: warning: conflicting outputs to file 'foo.output'
3f7ca628
JD
166])
167
168AT_CHECK_CONFLICTING_OUTPUT([foo.y],
169[%skeleton "lalr1.cc" %defines], [--graph="location.hh"],
9874f80b 170[foo.y: warning: conflicting outputs to file 'location.hh'
3f7ca628 171])
bd9d212b 172
c0ee9e21 173AT_CHECK_CONFLICTING_OUTPUT([foo.y], [], [-o foo.y],
9874f80b 174[foo.y: refusing to overwrite the input file 'foo.y'
c0ee9e21
DJ
175], 1)
176
bd9d212b
JD
177
178# AT_CHECK_OUTPUT_FILE_NAME(FILE-NAME-PREFIX, [ADDITIONAL-TESTS])
290a8ff2 179# ---------------------------------------------------------------
bd9d212b
JD
180m4_define([AT_CHECK_OUTPUT_FILE_NAME],
181[AT_SETUP([Output file name: $1])
182
290a8ff2 183AT_BISON_OPTION_PUSHDEFS
9637e0ed
JD
184# Skip if platform doesn't support file name. For example, Cygwin
185# doesn't support file names containing ":" or "\".
186AT_CHECK([[touch "]AS_ESCAPE([$1[.tmp]])[" || exit 77]])
187
ce3448d5 188AT_DATA_GRAMMAR([glr.y],
bd9d212b
JD
189[[%glr-parser
190%code {
290a8ff2
AD
191]AT_YYERROR_DECLARE_EXTERN[
192]AT_YYLEX_DECLARE_EXTERN[
bd9d212b
JD
193}
194%%
195start: {};
196]])
da730230 197AT_BISON_CHECK([-o "AS_ESCAPE([$1.c])" --defines="AS_ESCAPE([$1.h])" glr.y])
bd9d212b
JD
198AT_CHECK([ls "AS_ESCAPE([$1.c])" "AS_ESCAPE([$1.h])"], [], [ignore])
199AT_COMPILE([glr.o], [-c "AS_ESCAPE([$1.c])"])
200$2
201
ce3448d5 202AT_DATA_GRAMMAR([cxx.y],
bd9d212b
JD
203[[%skeleton "lalr1.cc"
204%code { int yylex (yy::parser::semantic_type*); }
205%%
206start: {};
207]])
da730230 208AT_BISON_CHECK([-o "AS_ESCAPE([$1.c])" --defines="AS_ESCAPE([$1.h])" cxx.y])
bd9d212b
JD
209AT_CHECK([ls "AS_ESCAPE([$1.c])" "AS_ESCAPE([$1.h])"], [], [ignore])
210AT_COMPILE_CXX([cxx.o], [-c "AS_ESCAPE([$1.c])"])
211$2
212
290a8ff2 213AT_BISON_OPTION_POPDEFS
bd9d212b
JD
214AT_CLEANUP
215])
216
217# Notice that the header file name here cannot contain
9874f80b 218# '"' since FILENAME in '#include "FILENAME"' cannot.
bd9d212b 219AT_CHECK_OUTPUT_FILE_NAME([[`~!@#$%^&*()-=_+{}[]|\:;<>, .']])
f55efa38
JD
220dnl Work around a bug in m4_expand that broke AT_SETUP in autoconf 2.62,
221dnl by using the definition from 2.63.
bee1df15
EB
222m4_version_prereq([2.63], [],
223[m4_define([m4_expand], [_$0(-=<{($1)}>=-)])
f55efa38 224m4_define([_m4_expand],
bee1df15 225[m4_changequote([-=<{(], [)}>=-])$1m4_changequote([, ])])])
f55efa38
JD
226AT_CHECK_OUTPUT_FILE_NAME([[(]])
227AT_CHECK_OUTPUT_FILE_NAME([[)]])
b4d71a96 228AT_CHECK_OUTPUT_FILE_NAME([[@%:@]])
bd9d212b
JD
229AT_CHECK_OUTPUT_FILE_NAME([[@@]])
230AT_CHECK_OUTPUT_FILE_NAME([[@{]])
231AT_CHECK_OUTPUT_FILE_NAME([[@}]])
bd9d212b
JD
232AT_CHECK_OUTPUT_FILE_NAME([[@<:@]])
233AT_CHECK_OUTPUT_FILE_NAME([[@:>@]])