tests: use more POSIX shell features our test scripts
[platform/upstream/automake.git] / t / yacc-cxx.sh
1 #! /bin/sh
2 # Copyright (C) 2011-2012 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, see <http://www.gnu.org/licenses/>.
16
17 # Basic semantic checks on Yacc + C++ support (when yacc-generated
18 # headers are not involved).
19 # Keep in sync with sister test 'yacc-basic.test'.
20
21 required='c++ yacc'
22 . ./defs || Exit 1
23
24 cat >> configure.ac << 'END'
25 AC_PROG_CXX
26 AC_PROG_YACC
27 AC_OUTPUT
28 END
29
30 cat > Makefile.am << 'END'
31 bin_PROGRAMS = foo1 foo2 foo3 foo4
32 foo1_SOURCES = parse1.yy  foo.cc
33 foo2_SOURCES = parse2.y++ bar.c++
34 foo3_SOURCES = parse3.yxx foo.cc
35 foo4_SOURCES = parse4.ypp bar2.cxx
36 foo3_YFLAGS = -v
37 foo4_YFLAGS = $(foo3_YFLAGS)
38
39 .PHONY: echo-distcom
40 echo-distcom:
41         @echo ' ' $(DIST_COMMON) ' '
42 END
43
44 cat > parse1.yy << 'END'
45 %{
46 // Valid C++, but deliberately invalid C.
47 #include <cstdio>
48 #include <cstdlib>
49 // "std::" qualification required by Sun C++ 5.9.
50 int yylex (void) { return std::getchar (); }
51 void yyerror (const char *s) { return; }
52 %}
53 %%
54 a : 'a' { exit(0); };
55 END
56 cp parse1.yy parse2.y++
57 cp parse1.yy parse3.yxx
58 cp parse1.yy parse4.ypp
59
60 cat > foo.cc << 'END'
61 // Valid C++, but deliberately invalid C.
62 using namespace std;
63 int main (int argc, char **argv)
64 {
65   int yyparse (void);
66   yyparse ();
67   return 1;
68 }
69 END
70 cp foo.cc bar.c++
71 cp foo.cc bar2.cxx
72
73 $ACLOCAL
74 $AUTOCONF
75 $AUTOMAKE -a
76
77 ./configure
78
79 $MAKE
80
81 # The Yacc-derived C++ sources must be created, and not removed once
82 # compiled (i.e., not treated like "intermediate files" in the GNU
83 # make sense).
84 test -f parse1.cc
85 test -f parse2.c++
86 test -f foo3-parse3.cxx
87 test -f foo4-parse4.cpp
88 # Check that per-object flags are honored.
89 test -f foo3-parse3.output
90 test -f foo4-parse4.output
91
92 if ! cross_compiling; then
93   for i in 1 2 3 4; do
94     echo a | ./foo$i
95     echo b | ./foo$i && Exit 1
96     : For shells with busted 'set -e'.
97   done
98 fi
99
100 # The Yacc-derived C++ sources must be shipped.
101 $MAKE echo-distcom
102 $MAKE -s echo-distcom | grep '[ /]parse1\.cc '
103 $MAKE -s echo-distcom | grep '[ /]parse2\.c++ '
104 $MAKE -s echo-distcom | grep '[ /]foo3-parse3\.cxx '
105 $MAKE -s echo-distcom | grep '[ /]foo4-parse4\.cpp '
106 $MAKE distdir
107 ls -l $distdir
108 test -f $distdir/parse1.cc
109 test -f $distdir/parse2.c++
110 test -f $distdir/foo3-parse3.cxx
111 test -f $distdir/foo4-parse4.cpp
112
113 # Sanity check on distribution.
114 # Note that, for this to succeed, foo3-parse3.output and foo4-parse4.output
115 # must either not be distributed, or properly cleaned by automake-generated
116 # rules.  We don't want to set the exact semantics yet, but want to ensure
117 # they are are consistent.
118 yl_distcheck
119
120 # Make sure that the Yacc-derived C++ sources are erased by
121 # maintainer-clean, and not by distclean.
122 test -f parse1.cc
123 test -f parse2.c++
124 test -f foo3-parse3.cxx
125 test -f foo4-parse4.cpp
126 $MAKE distclean
127 ls -l
128 test -f parse1.cc
129 test -f parse2.c++
130 test -f foo3-parse3.cxx
131 test -f foo4-parse4.cpp
132 ./configure # Re-create 'Makefile'.
133 $MAKE maintainer-clean
134 ls -l
135 test ! -f parse1.cc
136 test ! -f parse2.c++
137 test ! -f foo3-parse3.cxx
138 test ! -f foo4-parse4.cpp
139
140 :