test harness: improve catching of usage errors in script 'test-driver'
[platform/upstream/automake.git] / t / aclocal-macrodir.tap
1 #! /bin/sh
2 # Copyright (C) 2012-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 # Several tests on the use of the m4 macro AC_CONFIG_MACRO_DIR with
18 # aclocal.  See also related test 'aclocal-macrodir.tap'.
19
20 am_create_testdir=empty
21 . test-init.sh
22
23 plan_ 7
24
25 ocwd=$(pwd) || fatal_ "getting current working directory"
26 unset ACLOCAL_PATH
27
28 #
29 # General utility functions and variables.
30 #
31 # TODO: These should maybe be refactored, generalized and
32 #       moved into 't/ax/tap-functions.sh' ...
33 #
34
35 tcount=0
36 r=invalid
37 description=''
38 directive=''
39
40 test_begin ()
41 {
42   if test -n "$description"; then
43     fatal_ "'test_begin' called, but another test seems active already"
44   else
45     r=ok
46     description=$1
47     directive=${2-}
48     echo "$description" > README.txt
49     shift
50   fi
51   tcount=$(($tcount + 1)) && test $tcount -gt 0 \
52     || fatal_ "failed to bump the test count"
53   mkdir $tcount.d
54   cd $tcount.d
55 }
56
57 test_end ()
58 {
59   if test -z "$description"; then
60     fatal_ "'test_end' called, but no test seems active"
61   else
62     cd "$ocwd" || fatal_ "cannot chdir back to top-level directory"
63     result_ "$r" -D "$directive" -- "$description"
64     # Don't leave directories for successful subtests hanging around.
65     if test -z "$directive" && test "$r" = ok; then
66       rm -rf "$tcount.d" || fatal_ "removing subdir $tcount.d"
67     fi
68     r=invalid directive= description=
69   fi
70 }
71
72 #---------------------------------------------------------------------------
73
74 test_begin "AC_CONFIG_MACRO_DIR is honored"
75
76 cat > configure.ac <<'END'
77 AC_INIT([md], [10.0])
78 AC_CONFIG_MACRO_DIR([macro-dir])
79 MY_FOO
80 END
81
82 mkdir macro-dir
83 echo 'AC_DEFUN([MY_FOO], [::my::foo::])' > macro-dir/foo.m4
84
85 $ACLOCAL \
86   && $FGREP 'm4_include([macro-dir/foo.m4])' aclocal.m4 \
87   && $AUTOCONF \
88   && not $FGREP 'MY_FOO' configure \
89   && $FGREP '::my::foo::' configure \
90   || r='not ok'
91
92 test_end
93
94 #---------------------------------------------------------------------------
95
96 test_begin "AC_CONFIG_MACRO_DIR([foo]) interaction with --install"
97
98 cat > configure.ac << 'END'
99 AC_INIT([inst], [1.0])
100 AC_CONFIG_MACRO_DIR([the-dir])
101 THE_MACRO
102 END
103
104 mkdir sys-dir the-dir
105 echo 'AC_DEFUN([THE_MACRO], [:])' > sys-dir/my.m4
106
107 test ! -r the-dir/my.m4 \
108   && $ACLOCAL --install --system-acdir ./sys-dir \
109   && diff sys-dir/my.m4 the-dir/my.m4 \
110   || r='not ok'
111
112 test_end
113
114 #---------------------------------------------------------------------------
115
116 test_begin "'-I' option wins over AC_CONFIG_MACRO_DIR"
117
118 cat > configure.ac <<'END'
119 AC_INIT([md], [4.6])
120 AC_CONFIG_MACRO_DIR([dir1])
121 MY_FOO
122 END
123
124 mkdir dir1 dir2
125 echo 'AC_DEFUN([MY_FOO], [::ko::ko::])' > dir1/1.m4
126 echo 'AC_DEFUN([MY_FOO], [::ok::ok::])' > dir2/2.m4
127
128 $ACLOCAL -I dir2 \
129   && $FGREP 'm4_include([dir2/2.m4])' aclocal.m4 \
130   && not $FGREP 'm4_include([dir1/1.m4])' aclocal.m4 \
131   && $AUTOCONF \
132   && not $FGREP '::ko::ko::' configure \
133   && $FGREP '::ok::ok::' configure \
134   || r='not ok'
135
136 test_end
137
138 #---------------------------------------------------------------------------
139
140 test_begin "AC_CONFIG_MACRO_DIR([foo]) can create directory 'foo'"
141
142 cat > configure.ac << 'END'
143 AC_INIT([x], [1.0])
144 AC_CONFIG_MACRO_DIR([foo])
145 MY_MACRO
146 END
147
148 mkdir acdir
149 echo 'AC_DEFUN([MY_MACRO], [:])' > acdir/bar.m4
150
151 test ! -d foo \
152   && $ACLOCAL --install --system-acdir ./acdir \
153   && diff acdir/bar.m4 foo/bar.m4 \
154   || r='not ok'
155
156 test_end
157
158 #---------------------------------------------------------------------------
159
160 test_begin "AC_CONFIG_MACRO_DIR([non-existent]) warns with -Wunsupported"
161
162 cat > configure.ac << 'END'
163 AC_INIT([oops], [1.0])
164 AC_CONFIG_MACRO_DIR([non-existent])
165 AM_INIT_AUTOMAKE
166 END
167
168 $ACLOCAL -Wno-error 2>stderr \
169   && cat stderr >&2 \
170   && grep "couldn't open directory 'non-existent'" stderr \
171   && test -f aclocal.m4 \
172   || r='not ok'
173
174 rm -rf aclocal.m4 autom4te*.cache
175
176 $ACLOCAL -Werror -Wno-unsupported \
177   && test -f aclocal.m4 \
178   || r='not ok'
179
180 test_end
181
182 #---------------------------------------------------------------------------
183
184 test_begin "AC_CONFIG_MACRO_DIR([not-exist]) and ACLOCAL_AMFLAGS = -I not-exist"
185
186 cat > configure.ac << 'END'
187 AC_INIT([oops], [1.0])
188 AC_CONFIG_MACRO_DIR([not-exist])
189 END
190
191 cat > Makefile.am << 'END'
192 ACLOCAL_AMFLAGS = -I not-exist
193 END
194
195 $ACLOCAL -Wno-error 2>stderr \
196   && cat stderr >&2 \
197   && test $(grep -c "couldn't open directory 'not-exist'" stderr) -eq 1 \
198   || r='not ok'
199
200 test_end
201
202 #---------------------------------------------------------------------------
203
204 # Avoid spurious failures with pre-2.70 autoconf.
205 # FIXME: remove this in automake 2.0, once we require Autoconf 2.70.
206 if echo 'AC_INIT AC_CONFIG_MACRO_DIRS' | $AUTOCONF -o/dev/null -; then
207
208   test_begin "AC_CONFIG_MACRO_DIR interaction with AC_REQUIRE"
209
210   unindent > configure.ac <<'END'
211   AC_INIT([req], [1.0])
212   AC_CONFIG_MACRO_DIR([macro-dir])
213   AC_DEFUN([MY_FOO], [AC_REQUIRE([MY_BAR])])
214   MY_FOO
215 END
216
217   mkdir macro-dir
218   echo 'AC_DEFUN([MY_BAR], [//my//bar//])' > macro-dir/x.m4
219
220   st=0; $ACLOCAL 2>stderr || st=$?
221   cat stderr >&2
222
223   test $st -eq 0 \
224     && test ! -s stderr \
225     && $FGREP 'm4_include([macro-dir/x.m4])' aclocal.m4 \
226     && $AUTOCONF \
227     && not $EGREP 'MY_(FOO|BAR)' configure \
228     && $FGREP '//my//bar//' configure \
229     || r='not ok'
230
231   test_end
232
233 else
234
235   skip_ -r "autoconf is too old (AC_CONFIG_MACRO_DIRS not defined)"
236
237 fi
238
239 :