test harness: improve catching of usage errors in script 'test-driver'
[platform/upstream/automake.git] / t / aclocal-serial.sh
1 #! /bin/sh
2 # Copyright (C) 2005-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 for --install with #serial numbers.
18
19 am_create_testdir=empty
20 . test-init.sh
21
22 cat > configure.ac << 'END'
23 AC_INIT
24 AM_MACRO1
25 AM_MACRO2
26 END
27
28 mkdir 1 2 3 4 5 6
29
30 cat >1/m1.m4 <<EOF
31 #serial 1.8.1230.9
32 AC_DEFUN([AM_MACRO1], [:macro11:])
33 AC_DEFUN([AM_MACRO2], [:macro21:])
34 EOF
35
36 cat >2/m1.m4 <<EOF
37 #serial 1.8.1231.9
38 AC_DEFUN([AM_MACRO1], [:macro12:])
39 EOF
40
41 cat >3/m2.m4 <<EOF
42 #serial 13
43 AC_DEFUN([AM_MACRO2], [:macro23:])
44 EOF
45
46 cat >3/m1.m4 <<EOF
47 #serial 1.8.1230.1
48 AC_DEFUN([AM_MACRO1], [:macro13:])
49 EOF
50
51 cat >4/mumble.m4 <<EOF
52 #serial 0
53 AC_DEFUN([AM_MACRO1], [:macro14:])
54 EOF
55
56 cat >5/ill-formed.m4 <<EOF
57 #serial bla
58 #serial .2
59 #serial
60 AC_DEFUN([AM_MACRO1], [:macro15:])
61 EOF
62
63 cat >6/after-def.m4 <<EOF
64 AC_DEFUN([AM_MACRO1], [:macro16:])
65 #serial 1
66 EOF
67
68 clean_stale ()
69 {
70   rm -rf aclocal.m4 configure autom4te*.cache
71 }
72
73 $ACLOCAL -I 1 -I 2 -I 3 -I 4
74 $AUTOCONF
75 $FGREP ':macro11:' configure
76 $FGREP ':macro21:' configure
77
78 clean_stale
79 $ACLOCAL  -I 1 -I 2 -I 3 -I 4 --install
80 $AUTOCONF
81 $FGREP ':macro12:' configure
82 $FGREP ':macro23:' configure
83
84 cp -f aclocal.m4 aclocal-m4.sav
85 clean_stale
86 mv -f aclocal-m4.sav aclocal.m4
87 $ACLOCAL -I 4 -I 1 -I 2 -I 3 --install --dry-run
88 $AUTOCONF
89 $FGREP ':macro12:' configure
90 $FGREP ':macro23:' configure
91
92 clean_stale
93 $ACLOCAL -I 4 -I 1 -I 2 -I 3 --install
94 $AUTOCONF
95 $FGREP ':macro14:' configure
96 $FGREP ':macro23:' configure
97
98 clean_stale
99 $ACLOCAL -I 4 -I 1 -I 2 --install 2>stderr && { cat stderr >&2; exit 1; }
100 cat stderr >&2
101 grep 'macro.*AM_MACRO2.*not found' stderr
102
103 clean_stale
104 $ACLOCAL -I 4 -I 1 --install
105 $AUTOCONF
106 $FGREP ':macro14:' configure
107 $FGREP ':macro21:' configure
108
109 mkdir acdir
110 ACLOCAL="$ACLOCAL --system-acdir acdir"
111
112 cat >acdir/m1.m4 <<EOF
113 #serial 456
114 AC_DEFUN([AM_MACRO1], [:macro1d:])
115 AC_DEFUN([AM_MACRO2], [:macro2d:])
116 EOF
117 clean_stale
118 $ACLOCAL -I 4 -I 1 --diff=diff >stdout 2>stderr || {
119   cat stderr >&2
120   cat stdout
121   exit 1
122 }
123 cat stderr >&2
124 cat stdout
125 grep '#serial 456' stdout
126 test ! -e 4/m1.m4
127 grep 'installing.*4/m1\.m4' stderr
128
129 $ACLOCAL -I 5 2>stderr && { cat stderr >&2; exit 1; }
130 cat stderr >&2
131 test $(grep -c 'ill-formed serial' stderr) -eq 3
132
133 $ACLOCAL -I 6 2>stderr && { cat stderr >&2; exit 1; }
134 cat stderr >&2
135 grep 'serial.*before any macro definition' stderr
136
137 :