Merge branch 'yacc-quote-fix'
[automake.git] / tests / yacc-line.test
blob4475b08579ec46413461a1d024eb967cb5628a17
1 #! /bin/sh
2 # Copyright (C) 2001-2012 Free Software Foundation, Inc.
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.
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.
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/>.
17 # Check that automake yacc support ensures that yacc-generated C
18 # files use correct "#line" directives. Try also with the
19 # `subdir-object' option enabled.
20 # See also sister test `lex-line.test'.
22 required=yacc
23 . ./defs || Exit 1
25 set -e
27 cat >> configure.in << 'END'
28 AC_CONFIG_FILES([sub/Makefile])
29 AC_PROG_CC
30 AM_PROG_CC_C_O
31 AC_PROG_YACC
32 AC_OUTPUT
33 END
35 mkdir dir sub sub/dir
37 cat > Makefile.am << 'END'
38 SUBDIRS = sub
39 bin_PROGRAMS = foo bar
40 AM_YFLAGS = -d
41 bar_YFLAGS =
42 foo_SOURCES = zardoz.y
43 bar_SOURCES = dir/quux.y
44 ## Avoid spurious failures with Solaris make.
45 zardoz.@OBJEXT@: zardoz.c
46 bar-quux.@OBJEXT@: bar-quux.c
47 END
49 cat > sub/Makefile.am << 'END'
50 AUTOMAKE_OPTIONS = subdir-objects
51 noinst_PROGRAMS = foo bar
52 foo_YFLAGS = -d
53 foo_SOURCES = zardoz.y
54 bar_SOURCES = dir/quux.y
55 ## Avoid spurious failures with Solaris make.
56 foo-zardoz.@OBJEXT@: foo-zardoz.c
57 dir/quux.@OBJEXT@: dir/quux.c
58 END
60 cat > zardoz.y << 'END'
62 int yylex () { return 0; }
63 void yyerror (char *s) { return; }
66 x : 'x' {};
68 int main(void)
70 return yyparse ();
72 END
74 cp zardoz.y dir/quux.y
75 cp zardoz.y sub/zardoz.y
76 cp zardoz.y sub/dir/quux.y
78 c_outputs='zardoz.c bar-quux.c sub/foo-zardoz.c sub/dir/quux.c'
80 $ACLOCAL
81 $AUTOCONF
82 $AUTOMAKE -a
84 for vpath in : false; do
86 if $vpath; then
87 srcdir=..
88 mkdir build
89 cd build
90 else
91 srcdir=.
94 $srcdir/configure
95 $MAKE
97 # For debugging,
98 ls -l . sub sub/dir
99 $FGREP '.y' $c_outputs
101 # Adjusted "#line" should not contain reference to the builddir.
102 $EGREP '#.*line.*(build|\.\.).*\.y' $c_outputs && Exit 1
103 # Adjusted "#line" should not contain reference to the default
104 # output file names, e.g., `y.tab.c' and `y.tab.h'.
105 $EGREP '#.*line.*y\.tab\.' $c_outputs && Exit 1
106 # Don't be excessively strict in grepping, to avoid spurious failures.
107 grep '#.*line.*zardoz\.y' zardoz.c
108 grep '#.*line.*quux\.y' bar-quux.c
109 grep '#.*line.*zardoz\.y' sub/foo-zardoz.c
110 grep '#.*line.*quux\.y' sub/dir/quux.c
111 cd $srcdir
113 done