aclocal: diagnose non-existing directories in AC_CONFIG_MACRO_DIRS better
[platform/upstream/automake.git] / t / aclocal-macrodirs.tap
1 #! /bin/sh
2 # Copyright (C) 2012 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_DIRS with
18 # aclocal.  See also related test 'aclocal-macrodir.tap'.
19
20 am_create_testdir=empty
21 . test-init.sh
22
23 { $AUTOCONF -o /dev/null - <<END
24     AC_INIT([x], [0])
25     AC_CONFIG_MACRO_DIRS([.])
26 END
27 } || skip_all_ "autoconf doesn't define the AC_CONFIG_MACRO_DIRS macro"
28
29 plan_ 11
30
31 ocwd=$(pwd) || fatal_ "getting current working directory"
32 ACLOCAL_PATH=; unset ACLOCAL_PATH
33
34 #
35 # General utility functions and variables.
36 #
37 # TODO: These should maybe be refactored, generalized and
38 #       moved into 't/ax/tap-functions.sh' ...
39 #
40
41 tcount=0
42 r=invalid
43 description=''
44 directive=''
45
46 test_begin ()
47 {
48   if test -n "$description"; then
49     fatal_ "'test_begin' called, but another test seems active already"
50   else
51     r=ok
52     description=$1
53     directive=${2-}
54     echo "$description" > README.txt
55     shift
56   fi
57   tcount=$(($tcount + 1)) && test $tcount -gt 0 \
58     || fatal_ "failed to bump the test count"
59   mkdir $tcount.d
60   cd $tcount.d
61 }
62
63 test_end ()
64 {
65   if test -z "$description"; then
66     fatal_ "'test_end' called, but no test seems active"
67   else
68     cd "$ocwd" || fatal_ "cannot chdir back to top-level directory"
69     result_ "$r" -D "$directive" -- "$description"
70     # Don't leave directories for successful subtests hanging around.
71     if test -z "$directive" && test "$r" = ok; then
72       rm -rf "$tcount.d" || fatal_ "removing subdir $tcount.d"
73     fi
74     r=invalid directive= description=
75   fi
76 }
77
78 #---------------------------------------------------------------------------
79
80 test_begin "AC_CONFIG_MACRO_DIRS is honored"
81
82 cat > configure.ac <<'END'
83 AC_INIT([md], [10.0])
84 AC_CONFIG_MACRO_DIRS([macro-dir])
85 MY_FOO
86 END
87
88 mkdir macro-dir
89 echo 'AC_DEFUN([MY_FOO], [::my::foo::])' > macro-dir/foo.m4
90
91 $ACLOCAL \
92   && $FGREP 'm4_include([macro-dir/foo.m4])' aclocal.m4 \
93   && $AUTOCONF \
94   && not $FGREP 'MY_FOO' configure \
95   && $FGREP '::my::foo::' configure \
96   || r='not ok'
97
98 test_end
99
100 #---------------------------------------------------------------------------
101
102 two_dirs_check ()
103 {
104   mkdir dir1 dir2
105   echo 'AC_DEFUN([MY_FOO], [::my::foo::])' > dir1/foo.m4
106   echo 'AC_DEFUN([MY_BAR], [!!my!!bar!!])' > dir2/zap.m4
107   $ACLOCAL \
108     && $FGREP 'm4_include([dir1/foo.m4])' aclocal.m4 \
109     && $FGREP 'm4_include([dir2/zap.m4])' aclocal.m4 \
110     && $AUTOCONF \
111     && not $EGREP 'MY_(FOO|BAR)' configure \
112     && $FGREP '::my::foo::' configure \
113     && $FGREP '!!my!!bar!!' configure \
114     || r='not ok'
115 }
116
117 #---------------------------------------------------------------------------
118
119 test_begin "AC_CONFIG_MACRO_DIRS: several arguments"
120
121 cat > configure.ac <<'END'
122 AC_INIT([more-args], [0.2])
123 AC_CONFIG_MACRO_DIRS([dir1 dir2])
124 MY_FOO
125 MY_BAR
126 END
127
128 two_dirs_check
129
130 test_end
131
132 #---------------------------------------------------------------------------
133
134 test_begin "AC_CONFIG_MACRO_DIRS: several calls"
135
136 cat > configure.ac <<'END'
137 AC_INIT([more-calls], [2.0])
138 AC_CONFIG_MACRO_DIRS([dir1])
139 AC_CONFIG_MACRO_DIRS([dir2])
140 MY_FOO
141 MY_BAR
142 END
143
144 two_dirs_check
145
146 test_end
147
148 #---------------------------------------------------------------------------
149
150 test_begin "AC_CONFIG_MACRO_DIRS interaction with --install"
151
152 cat > configure.ac << 'END'
153 AC_INIT([inst], [1.0])
154 AC_CONFIG_MACRO_DIRS([the-dir])
155 THE_MACRO
156 END
157
158 mkdir sys-dir the-dir
159 echo 'AC_DEFUN([THE_MACRO], [:])' > sys-dir/my.m4
160
161 test ! -r the-dir/my.m4 \
162   && $ACLOCAL --install --system-acdir ./sys-dir \
163   && diff sys-dir/my.m4 the-dir/my.m4 \
164   || r='not ok'
165
166 test_end
167
168 #---------------------------------------------------------------------------
169
170 two_dirs_install_check ()
171 {
172   mkdir sys-dir dir1 dir2
173   echo 'AC_DEFUN([THE_MACRO], [:])' > sys-dir/my.m4
174   echo 'AC_DEFUN([AX_FOO], [:])' > dir2/zap.m4
175   test ! -r dir1/my.m4 \
176     && $ACLOCAL --install --system-acdir ./sys-dir \
177     && diff sys-dir/my.m4 dir1/my.m4 \
178     && test ! -e dir2/my.m4 \
179     && $FGREP 'm4_include([dir1/my.m4])' aclocal.m4 \
180     && $FGREP 'm4_include([dir2/zap.m4])' aclocal.m4 \
181     || r='not ok'
182 }
183
184 #---------------------------------------------------------------------------
185
186 test_begin "several AC_CONFIG_MACRO_DIRS arguments and --install"
187
188 cat > configure.ac << 'END'
189 AC_INIT([inst2a], [1.0])
190 AC_CONFIG_MACRO_DIRS([dir1 dir2])
191 THE_MACRO
192 AX_FOO
193 END
194
195 two_dirs_install_check
196
197 test_end
198
199 #---------------------------------------------------------------------------
200
201
202 test_begin "several AC_CONFIG_MACRO_DIRS calls and --install"
203
204 cat > configure.ac << 'END'
205 AC_INIT([inst2b], [1.0])
206 AC_CONFIG_MACRO_DIRS([dir1])
207 AC_CONFIG_MACRO_DIRS([dir2])
208 THE_MACRO
209 AX_FOO
210 END
211
212 two_dirs_install_check
213
214 test_end
215
216 #---------------------------------------------------------------------------
217
218 test_begin "'-I' option wins over AC_CONFIG_MACRO_DIRS"
219
220 cat > configure.ac <<'END'
221 AC_INIT([md], [4.6])
222 AC_CONFIG_MACRO_DIRS([dir1])
223 MY_FOO
224 END
225
226 mkdir dir1 dir2
227 echo 'AC_DEFUN([MY_FOO], [::ko::ko::])' > dir1/1.m4
228 echo 'AC_DEFUN([MY_FOO], [::ok::ok::])' > dir2/2.m4
229
230 $ACLOCAL -I dir2 \
231   && $FGREP 'm4_include([dir2/2.m4])' aclocal.m4 \
232   && not $FGREP 'm4_include([dir1/1.m4])' aclocal.m4 \
233   && $AUTOCONF \
234   && not $FGREP '::ko::ko::' configure \
235   && $FGREP '::ok::ok::' configure \
236   || r='not ok'
237
238 test_end
239
240 #---------------------------------------------------------------------------
241
242 test_begin "AC_CONFIG_MACRO_DIRS([foo]) can create directory 'foo'"
243
244 cat > configure.ac << 'END'
245 AC_INIT([x], [1.0])
246 AC_CONFIG_MACRO_DIRS([foo])
247 MY_MACRO
248 END
249
250 mkdir acdir
251 echo 'AC_DEFUN([MY_MACRO], [:])' > acdir/bar.m4
252
253 test ! -d foo \
254   && $ACLOCAL --install --system-acdir ./acdir \
255   && diff acdir/bar.m4 foo/bar.m4 \
256   || r='not ok'
257
258 test_end
259
260 #---------------------------------------------------------------------------
261
262 test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) errors out (1)"
263
264 cat > configure.ac << 'END'
265 AC_INIT([oops], [1.0])
266 AC_CONFIG_MACRO_DIRS([non-existent])
267 END
268
269 not $ACLOCAL 2>stderr \
270   && cat stderr >&2 \
271   && grep "couldn't open directory 'non-existent'" stderr \
272   || r='not ok'
273
274 test_end
275
276 #---------------------------------------------------------------------------
277
278 test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) errors out (2)"
279
280 cat > configure.ac << 'END'
281 AC_INIT([oops], [1.0])
282 AC_CONFIG_MACRO_DIRS([dir-ok])
283 AC_CONFIG_MACRO_DIRS([dir-ko])
284 END
285
286 mkdir dir-ok
287 not $ACLOCAL 2>stderr \
288   && cat stderr >&2 \
289   && grep "couldn't open directory 'dir-ko'" stderr \
290   && not grep "dir-ok" stderr \
291   || r='not ok'
292
293 test_end
294
295 #---------------------------------------------------------------------------
296
297 test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) errors out (tricky setup)"
298
299 cat > configure.ac << 'END'
300 AC_INIT([oops], [1.0])
301 AC_CONFIG_MACRO_DIRS([dir-ok])
302 AC_CONFIG_MACRO_DIRS([dir-ko])
303 END
304
305 mkdir dir-ok
306
307 not $ACLOCAL -Wnone --install 2>stderr \
308   && cat stderr >&2 \
309   && grep "couldn't open directory 'dir-ko'" stderr \
310   && test ! -e dir-ko \
311   || r='not ok'
312
313 test_end
314
315 #---------------------------------------------------------------------------
316
317 :