tests: avoid a spurious failure on MSYS
[platform/upstream/automake.git] / t / aclocal-macrodirs.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_DIRS with
18 # aclocal.  See also related test 'aclocal-macrodir.tap'.
19
20 am_create_testdir=empty
21 . test-init.sh
22
23 plan_ 15
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_DIRS is honored"
75
76 cat > configure.ac <<'END'
77 AC_INIT([md], [10.0])
78 AC_CONFIG_MACRO_DIRS([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 three_dirs_check ()
97 {
98   mkdir dir1 dir2 dir3
99   echo 'AC_DEFUN([MY_FOO], [::my::foo::])' > dir1/foo.m4
100   echo 'AC_DEFUN([MY_BAR], [!!my!!bar!!])' > dir2/zap.m4
101   echo 'AC_DEFUN([MY_BAZ], [==my==baz==])' > dir3/0.m4
102   $ACLOCAL \
103     && $FGREP 'm4_include([dir1/foo.m4])' aclocal.m4 \
104     && $FGREP 'm4_include([dir2/zap.m4])' aclocal.m4 \
105     && $FGREP 'm4_include([dir3/0.m4])'   aclocal.m4 \
106     && $AUTOCONF \
107     && not $EGREP 'MY_(FOO|BAR|BAZ)' configure \
108     && $FGREP '::my::foo::' configure \
109     && $FGREP '!!my!!bar!!' configure \
110     && $FGREP '==my==baz==' configure \
111     || r='not ok'
112 }
113
114 #---------------------------------------------------------------------------
115
116 test_begin "AC_CONFIG_MACRO_DIRS several arguments"
117
118 cat > configure.ac <<'END'
119 AC_INIT([more-args], [0.2])
120 AC_CONFIG_MACRO_DIRS([dir1 dir2 dir3])
121 MY_FOO
122 MY_BAR
123 MY_BAZ
124 END
125
126 three_dirs_check
127
128 test_end
129
130 #---------------------------------------------------------------------------
131
132 test_begin "AC_CONFIG_MACRO_DIRS several calls"
133
134 cat > configure.ac <<'END'
135 AC_INIT([more-calls], [2.0])
136 AC_CONFIG_MACRO_DIRS([dir1])
137 AC_CONFIG_MACRO_DIRS([dir2 dir3])
138 MY_FOO
139 MY_BAR
140 MY_BAZ
141 END
142
143 three_dirs_check
144
145 test_end
146
147 #---------------------------------------------------------------------------
148
149 test_begin "AC_CONFIG_MACRO_DIRS extra whitespace"
150
151 bslash=\\
152
153 cat > configure.ac <<END
154 AC_INIT([more-args], [0.2])
155 AC_CONFIG_MACRO_DIRS([   dir1${bslash}
156 ${tab} dir2   ${tab}${tab}dir3
157 ${bslash}
158
159 ])
160 MY_FOO
161 MY_BAR
162 MY_BAZ
163 END
164
165 three_dirs_check
166
167 test_end
168
169 #---------------------------------------------------------------------------
170
171 test_begin "AC_CONFIG_MACRO_DIRS precedence"
172
173 cat > configure.ac <<'END'
174 AC_INIT([more-calls], [2.0])
175 AC_CONFIG_MACRO_DIRS([dir1])
176 AC_CONFIG_MACRO_DIRS([dir2 dir3])
177 MY_FOO
178 MY_BAR
179 MY_BAZ
180 END
181
182 mkdir dir1 dir2 dir3
183 echo 'AC_DEFUN([MY_FOO], [OK-Foo])' > dir1/b.m4
184 echo 'AC_DEFUN([MY_FOO], [KO-Foo])' > dir2/a.m4
185 echo 'AC_DEFUN([MY_BAR], [OK-Bar])' > dir2/1.m4
186 echo 'AC_DEFUN([MY_BAR], [KO-Bar])' > dir3/0.m4
187 echo 'AC_DEFUN([MY_BAZ], [OK-Baz])' > dir3/x.m4
188
189 $ACLOCAL \
190   && $FGREP 'm4_include([dir1/b.m4])' aclocal.m4 \
191   && $FGREP 'm4_include([dir2/1.m4])' aclocal.m4 \
192   && $FGREP 'm4_include([dir3/x.m4])' aclocal.m4 \
193   && test $($FGREP -c 'm4_include([dir1' aclocal.m4) -eq 1 \
194   && test $($FGREP -c 'm4_include([dir2' aclocal.m4) -eq 1 \
195   && test $($FGREP -c 'm4_include([dir3' aclocal.m4) -eq 1 \
196   && $AUTOCONF \
197   && not $EGREP 'MY_(FOO|BAR|BAZ)' configure \
198   && $FGREP 'OK-Foo' configure \
199   && $FGREP 'OK-Bar' configure \
200   && $FGREP 'OK-Baz' configure \
201   && not $FGREP 'KO-' configure \
202   || r='not ok'
203
204 test_end
205
206 #---------------------------------------------------------------------------
207
208 test_begin "AC_CONFIG_MACRO_DIRS interaction with --install"
209
210 cat > configure.ac << 'END'
211 AC_INIT([inst], [1.0])
212 AC_CONFIG_MACRO_DIRS([the-dir])
213 THE_MACRO
214 END
215
216 mkdir sys-dir the-dir
217 echo 'AC_DEFUN([THE_MACRO], [:])' > sys-dir/my.m4
218
219 test ! -r the-dir/my.m4 \
220   && $ACLOCAL --install --system-acdir ./sys-dir \
221   && diff sys-dir/my.m4 the-dir/my.m4 \
222   || r='not ok'
223
224 test_end
225
226 #---------------------------------------------------------------------------
227
228 two_dirs_install_check ()
229 {
230   mkdir sys-dir dir1 dir2
231   echo 'AC_DEFUN([THE_MACRO], [:])' > sys-dir/my.m4
232   echo 'AC_DEFUN([AX_FOO], [:])' > dir2/zap.m4
233   test ! -r dir1/my.m4 \
234     && $ACLOCAL --install --system-acdir ./sys-dir \
235     && diff sys-dir/my.m4 dir1/my.m4 \
236     && test ! -e dir2/my.m4 \
237     && $FGREP 'm4_include([dir1/my.m4])' aclocal.m4 \
238     && $FGREP 'm4_include([dir2/zap.m4])' aclocal.m4 \
239     || r='not ok'
240 }
241
242 #---------------------------------------------------------------------------
243
244 test_begin "several AC_CONFIG_MACRO_DIRS arguments and --install"
245
246 cat > configure.ac << 'END'
247 AC_INIT([inst2a], [1.0])
248 AC_CONFIG_MACRO_DIRS([dir1 dir2])
249 THE_MACRO
250 AX_FOO
251 END
252
253 two_dirs_install_check
254
255 test_end
256
257 #---------------------------------------------------------------------------
258
259
260 test_begin "several AC_CONFIG_MACRO_DIRS calls and --install"
261
262 cat > configure.ac << 'END'
263 AC_INIT([inst2b], [1.0])
264 AC_CONFIG_MACRO_DIRS([dir1])
265 AC_CONFIG_MACRO_DIRS([dir2])
266 THE_MACRO
267 AX_FOO
268 END
269
270 two_dirs_install_check
271
272 test_end
273
274 #---------------------------------------------------------------------------
275
276 test_begin "'-I' option wins over AC_CONFIG_MACRO_DIRS"
277
278 cat > configure.ac <<'END'
279 AC_INIT([md], [4.6])
280 AC_CONFIG_MACRO_DIRS([dir1])
281 MY_FOO
282 END
283
284 mkdir dir1 dir2
285 echo 'AC_DEFUN([MY_FOO], [::ko::ko::])' > dir1/1.m4
286 echo 'AC_DEFUN([MY_FOO], [::ok::ok::])' > dir2/2.m4
287
288 $ACLOCAL -I dir2 \
289   && $FGREP 'm4_include([dir2/2.m4])' aclocal.m4 \
290   && not $FGREP 'm4_include([dir1/1.m4])' aclocal.m4 \
291   && $AUTOCONF \
292   && not $FGREP '::ko::ko::' configure \
293   && $FGREP '::ok::ok::' configure \
294   || r='not ok'
295
296 test_end
297
298 #---------------------------------------------------------------------------
299
300 test_begin "AC_CONFIG_MACRO_DIRS([foo]) can create directory 'foo'"
301
302 cat > configure.ac << 'END'
303 AC_INIT([x], [1.0])
304 AC_CONFIG_MACRO_DIRS([foo])
305 MY_MACRO
306 END
307
308 mkdir acdir
309 echo 'AC_DEFUN([MY_MACRO], [:])' > acdir/bar.m4
310
311 test ! -d foo \
312   && $ACLOCAL --install --system-acdir ./acdir \
313   && diff acdir/bar.m4 foo/bar.m4 \
314   || r='not ok'
315
316 test_end
317
318 #---------------------------------------------------------------------------
319
320 test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) warns (1)"
321
322 cat > configure.ac << 'END'
323 AC_INIT([oops], [1.0])
324 AC_CONFIG_MACRO_DIRS([non-existent])
325 AM_INIT_AUTOMAKE
326 END
327
328 $ACLOCAL -Wno-error 2>stderr \
329   && cat stderr >&2 \
330   && grep "couldn't open directory 'non-existent'" stderr \
331   && test -f aclocal.m4 \
332   || r='not ok'
333
334 rm -rf aclocal.m4 autom4te*.cache
335
336 $ACLOCAL -Werror -Wno-unsupported \
337   && test -f aclocal.m4 \
338   || r='not ok'
339
340 test_end
341
342 #---------------------------------------------------------------------------
343
344 test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) warns (2)"
345
346 cat > configure.ac << 'END'
347 AC_INIT([oops], [1.0])
348 AC_CONFIG_MACRO_DIRS([dir-ok])
349 AC_CONFIG_MACRO_DIRS([dir-ko])
350 END
351
352 mkdir dir-ok
353 not $ACLOCAL 2>stderr \
354   && cat stderr >&2 \
355   && grep "couldn't open directory 'dir-ko'" stderr \
356   && not grep "dir-ok" stderr \
357   && test ! -e aclocal.m4 \
358   || r='not ok'
359
360 test_end
361
362 #---------------------------------------------------------------------------
363
364 test_begin "AC_CONFIG_MACRO_DIRS([existent non-existent]) errors out"
365
366 cat > configure.ac << 'END'
367 AC_INIT([oops], [1.0])
368 AC_CONFIG_MACRO_DIRS([dir-ok])
369 AC_CONFIG_MACRO_DIRS([dir-ko])
370 END
371
372 mkdir dir-ok
373
374 not $ACLOCAL -Wnone --install 2>stderr \
375   && cat stderr >&2 \
376   && grep "couldn't open directory 'dir-ko'" stderr \
377   && test ! -e dir-ko \
378   || r='not ok'
379
380 test_end
381
382 #---------------------------------------------------------------------------
383
384 test_begin "AC_CONFIG_MACRO_DIRS([not-exist]) and ACLOCAL_AMFLAGS = -I not-exist"
385
386 cat > configure.ac << 'END'
387 AC_INIT([oops], [1.0])
388 AC_CONFIG_MACRO_DIRS([not-exist])
389 END
390
391 cat > Makefile.am << 'END'
392 ACLOCAL_AMFLAGS = -I not-exist
393 END
394
395 $ACLOCAL -Wno-error 2>stderr \
396   && cat stderr >&2 \
397   && test $(grep -c "couldn't open directory 'not-exist'" stderr) -eq 1 \
398   || r='not ok'
399
400 test_end
401
402 #---------------------------------------------------------------------------
403
404 # Avoid spurious failures with pre-2.70 autoconf.
405 # FIXME: remove this in automake 2.0, once we require Autoconf 2.70.
406 if echo 'AC_INIT AC_CONFIG_MACRO_DIRS' | $AUTOCONF -o/dev/null -; then
407
408   test_begin "AC_CONFIG_MACRO_DIRS interaction with AC_REQUIRE"
409
410   unindent > configure.ac <<'END'
411   AC_INIT([req], [1.0])
412   AC_CONFIG_MACRO_DIRS([m1 m2])
413   AC_DEFUN([MY_FOO], [
414     AC_REQUIRE([MY_BAR])
415     AC_REQUIRE([MY_BAZ])
416   ])
417   MY_FOO
418 END
419
420   mkdir m1 m2
421   echo 'AC_DEFUN([MY_BAR], [^^my^^bar^^])' > m1/x.m4
422   echo 'AC_DEFUN([MY_BAZ], [~~my~~baz~~])' > m2/x.m4
423
424   st=0; $ACLOCAL 2>stderr || st=$?
425   cat stderr >&2
426
427   test $st -eq 0 \
428     && test ! -s stderr \
429     && $FGREP 'm4_include([m1/x.m4])' aclocal.m4 \
430     && $FGREP 'm4_include([m2/x.m4])' aclocal.m4 \
431     && $AUTOCONF \
432     && not $EGREP 'MY_(FOO|BAR|BAZ)' configure \
433     && $FGREP '^^my^^bar^^' configure \
434     && $FGREP '~~my~~baz~~' configure \
435     || r='not ok'
436
437   test_end
438
439 else
440
441   skip_ -r "autoconf is too old (AC_CONFIG_MACRO_DIRS not defined)"
442
443 fi
444
445 :