tests: expose automake bug#14560
[platform/upstream/automake.git] / t / distcheck-missing-m4.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 # Test that we can define a distcheck-hook to diagnose m4 files
18 # missing from the dist tarball (interaction with '--install').
19 # See automake bug#9037.
20
21 . test-init.sh
22
23 cwd=$(pwd) || fatal_ "cannot get current working directory"
24
25 cp "$am_testaux_srcdir"/distcheck-hook-m4.am . \
26   || fatal_ "cannot fetch makefile fragment 'distcheck-hook-m4.am'"
27
28 cat > Makefile.am << 'END'
29 ## The lack of '--install' here is meant.
30 ACLOCAL_AMFLAGS = -I m4
31 include $(srcdir)/distcheck-hook-m4.am
32 END
33
34 cat >> configure.ac << 'END'
35 dnl We *deliberately* don't use m4_pattern_forbid here.
36 AC_OUTPUT
37 MY_FOO
38 MY_BAR
39 MY_BAZ
40 MY_ZAR
41 END
42
43 mkdir m4 acdir acdir1 acdir2 pth
44
45 cat > acdir/dirlist << END
46 $cwd/acdir1
47 $cwd/acdir2
48 END
49
50 echo 'AC_DEFUN([MY_FOO], [:])' > m4/foo.m4
51 echo 'AC_DEFUN([MY_BAR], [:])' > acdir1/bar.m4
52 echo 'AC_DEFUN([MY_BAZ], [:])' > acdir1/baz.m4
53 echo 'AC_DEFUN([MY_QUX], [:])' > acdir2/qux.m4
54 echo 'AC_DEFUN([MY_ZAR], [:])' > pth/zar.m4
55 echo 'AC_DEFUN([MY_BLA], [:])' > pth/bla.m4
56
57 ACLOCAL="$ACLOCAL --system-acdir=$cwd/acdir"; export ACLOCAL
58 ACLOCAL_PATH=$cwd/pth; export ACLOCAL_PATH
59
60 # We don't use '--install' here.  Our distcheck-hook should catch this.
61 $ACLOCAL -I m4
62 $AUTOCONF
63 $EGREP 'MY_(FOO|BAR|BAZ|ZAR)' configure && exit 1 # Sanity check.
64 $AUTOMAKE
65
66 check_no_spurious_error ()
67 {
68   $EGREP -i 'mkdir:|:.*(permission|denied)' output && exit 1
69   # On failure, some make implementations (such as Solaris make) print the
70   # whole failed recipe on stdout.  The first grep works around this.
71   grep -v 'rm -rf ' output | grep -i 'autom4te.*\.cache' && exit 1
72   : To placate 'set -e'.
73 }
74
75 ./configure
76
77 run_make -M -e FAIL distcheck
78 for x in bar baz zar; do
79   $EGREP "required m4 file.*not distributed.* $x.m4( |$)" output
80 done
81 check_no_spurious_error
82
83 # Now we use '--install', and "make distcheck" should pass.
84 $ACLOCAL -I m4 --install
85 test -f m4/bar.m4 # Sanity check.
86 test -f m4/baz.m4 # Likewise.
87 test -f m4/zar.m4 # Likewise.
88 using_gmake || $MAKE Makefile
89 $MAKE distcheck
90
91 # We start to use new "third-party" macros from new .m4 files, but forget
92 # to re-run "aclocal --install" by hand, relying on automatic remake rules.
93 # Our distcheck-hook should catch this too.
94 cat >> configure.ac << 'END'
95 MY_QUX
96 MY_BLA
97 END
98
99 $MAKE
100 $EGREP 'MY_(FOO|BAR|BAZ|QUX|ZAR|BLA)' configure && exit 1 # Sanity check.
101
102 run_make -M -e FAIL distcheck
103 $EGREP "required m4 file.*not distributed.* qux.m4( |$)" output
104 $EGREP "required m4 file.*not distributed.* bla.m4( |$)" output
105 check_no_spurious_error
106 # Check that we don't complain for files that should have been found.
107 $FGREP " (bar|baz|zar).m4" output && exit 1
108
109 # Now we again use '--install', and "make distcheck" should pass.
110 $ACLOCAL -I m4 --install
111 test -f m4/qux.m4 # Sanity check.
112 test -f m4/bla.m4 # Likewise.
113 using_gmake || $MAKE Makefile
114 $MAKE distcheck
115
116 :