test harness: improve catching of usage errors in script 'test-driver'
[platform/upstream/automake.git] / t / yacc-nodist.sh
1 #! /bin/sh
2 # Copyright (C) 2011-2013 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 # Checks for .c and .h files derived from non-distributed yacc sources.
18 # The test 'yacc-pr204.sh' does similar check with AM_MAINTAINER_MODE
19 # enabled.
20 # The tests 'lex-nodist.sh' and 'lex-pr204.sh' does similar checks
21 # for lex-generated .c files.
22
23 required='cc yacc'
24 . test-init.sh
25
26 cat >> configure.ac << 'END'
27 AC_PROG_CC
28 AC_PROG_YACC
29 AC_CONFIG_FILES([sub1/Makefile sub2/Makefile])
30 AC_OUTPUT
31 END
32
33 cat > Makefile.am << 'END'
34 SUBDIRS = sub1 sub2
35 .PHONY: test-build test-dist
36 test-build: all
37         ls -l . sub1 sub2
38         test -f sub1/parse.y
39         test -f sub1/parse.c
40         test -f sub2/parse.y
41         test -f sub2/parse.c
42         test -f sub2/parse.h
43 test-dist: distdir
44         ls -l $(distdir) $(distdir)/sub1 $(distdir)/sub2
45         test ! -r $(distdir)/sub1/parse.y
46         test ! -r $(distdir)/sub1/parse.c
47         test ! -r $(distdir)/sub1/parse.h
48         test ! -r $(distdir)/sub2/parse.y
49         test ! -r $(distdir)/sub2/parse.c
50         test ! -r $(distdir)/sub2/parse.h
51 check-local: test-build test-dist
52 END
53
54 mkdir sub1 sub2
55
56 cat > sub1/Makefile.am << 'END'
57 parse.y:
58         rm -f $@ $@-t
59         :; { : \
60           && echo "%{" \
61           && echo "int yylex () { return 0; }" \
62           && echo "void yyerror (char *s) {}" \
63           && echo "%}" \
64           && echo "%%" \
65           && echo "maude : 'm' 'a' 'u' 'd' 'e' {}"; \
66         } > $@-t
67         chmod a-w $@-t && mv -f $@-t $@
68
69 bin_PROGRAMS = prog
70 prog_SOURCES = main.c
71 nodist_prog_SOURCES = parse.y
72 CLEANFILES = $(nodist_prog_SOURCES)
73 END
74
75 cat sub1/Makefile.am - > sub2/Makefile.am << 'END'
76 AM_YFLAGS = -d
77 BUILT_SOURCES = parse.h
78 END
79
80 cat > sub1/main.c << 'END'
81 int main ()
82 {
83   return yyparse ();
84 }
85 END
86 cat - sub1/main.c > sub2/main.c << 'END'
87 #include "parse.h"
88 END
89
90 $ACLOCAL
91 $AUTOCONF
92 $AUTOMAKE -a
93
94 ./configure
95 $MAKE
96 $MAKE test-build
97 $MAKE test-dist
98
99 yl_distcheck
100
101 :