Merge branch 'minor'
[automake.git] / t / yacc-line.sh
blob326ff8a965bb1c8f2f72fc153817111c9fb95da1
1 #! /bin/sh
2 # Copyright (C) 2001-2017 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 <https://www.gnu.org/licenses/>.
17 # Check that automake yacc support ensures that yacc-generated C
18 # files use correct "#line" directives.
19 # See also sister test 'lex-line.test'.
21 required='cc yacc'
22 . test-init.sh
24 cat >> configure.ac << 'END'
25 AC_PROG_CC
26 AC_PROG_YACC
27 AC_OUTPUT
28 END
30 mkdir dir
32 cat > Makefile.am << 'END'
33 noinst_PROGRAMS = foo bar baz
34 baz_YFLAGS = -d
35 foo_SOURCES = zardoz.y
36 bar_SOURCES = dir/quux.y
37 baz_SOURCES = zardoz.y
38 END
40 cat > zardoz.y << 'END'
42 int yylex () { return 0; }
43 void yyerror (char *s) { return; }
46 x : 'x' {};
48 int main(void)
50 return yyparse ();
52 END
54 cp zardoz.y dir/quux.y
56 c_outputs='zardoz.c dir/quux.c baz-zardoz.c'
58 $ACLOCAL
59 $AUTOCONF
60 # FIXME: stop disabling the warnings in the 'unsupported' category
61 # FIXME: once the 'subdir-objects' option has been mandatory.
62 $AUTOMAKE -a -Wno-unsupported
64 for vpath in : false; do
66 if $vpath; then
67 srcdir=..
68 mkdir build
69 cd build
70 else
71 srcdir=.
74 $srcdir/configure
75 $MAKE
77 # For debugging,
78 ls -l . dir
79 $EGREP 'line|\.y' $c_outputs
81 # Adjusted "#line" should not contain reference to the builddir.
82 grep '#.*line.*build.*\.y' $c_outputs && exit 1
83 # Adjusted "#line" should not contain reference to the absolute
84 # srcdir.
85 $EGREP '#.*line *"?/.*\.y' $c_outputs && exit 1
86 # Adjusted "#line" should not contain reference to the default
87 # output file names, e.g., 'y.tab.c' and 'y.tab.h'.
88 grep '#.*line.*y\.tab\.' $c_outputs && exit 1
89 # Look out for a silly regression.
90 grep "#.*\.y.*\.y" $c_outputs && exit 1
91 if $vpath; then
92 grep '#.*line.*"\.\./zardoz\.y"' zardoz.c
93 grep '#.*line.*"\.\./zardoz\.y"' baz-zardoz.c
94 grep '#.*line.*"\.\./dir/quux\.y"' dir/quux.c
95 else
96 grep '#.*line.*"zardoz\.y"' zardoz.c
97 grep '#.*line.*"zardoz\.y"' baz-zardoz.c
98 grep '#.*line.*"dir/quux\.y"' dir/quux.c
101 cd $srcdir
103 done