Merge branch 'maint'
[platform/upstream/automake.git] / t / aclocal-macrodir.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_DIR with
18 # aclocal.
19
20 am_create_testdir=empty
21 . ./defs || exit 1
22
23 plan_ later
24
25 ocwd=$(pwd) || fatal_ "getting current working directory"
26 ACLOCAL_PATH=; 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     echo "$description" > README.txt
48     shift
49   fi
50   tcount=$(($tcount + 1)) && test $tcount -gt 0 \
51     || fatal_ "failed to bump the test count"
52   mkdir $tcount.d
53   cd $tcount.d
54 }
55
56 test_end ()
57 {
58   if test -z "$description"; then
59     fatal_ "'test_end' called, but no test seems active"
60   else
61     cd "$ocwd" || fatal_ "cannot chdir back to top-level directory"
62     result_ "$r" -D "$directive" -- "$description"
63     # Don't leave directories for successful subtests hanging around.
64     if test -z "$directive" && test "$r" = ok; then
65       rm -rf "$tcount.d" || fatal_ "removing subdir $tcount.d"
66     fi
67     r=invalid directive= description=
68   fi
69 }
70
71 test_todo () { directive=TODO; }
72
73 #---------------------------------------------------------------------------
74
75 test_begin "AC_CONFIG_MACRO_DIR is honored"
76
77 cat > configure.ac <<'END'
78 AC_INIT([md], [10.0])
79 AC_CONFIG_MACRO_DIR([macro-dir])
80 MY_FOO
81 END
82
83 mkdir macro-dir
84 echo 'AC_DEFUN([MY_FOO], [::my::foo::])' > macro-dir/foo.m4
85
86 $ACLOCAL \
87   && $FGREP 'm4_include([macro-dir/foo.m4])' aclocal.m4 \
88   && $AUTOCONF \
89   && not $FGREP 'MY_FOO' configure \
90   && $FGREP '::my::foo::' configure \
91   || r='not ok'
92
93 test_end
94
95 #---------------------------------------------------------------------------
96
97 test_begin "AC_CONFIG_MACRO_DIR([foo]) interaction with --install"
98
99 cat > configure.ac << 'END'
100 AC_INIT([inst], [1.0])
101 AC_CONFIG_MACRO_DIR([the-dir])
102 THE_MACRO
103 END
104
105 mkdir sys-dir the-dir
106 echo 'AC_DEFUN([THE_MACRO], [:])' > sys-dir/my.m4
107
108 test ! -r the-dir/my.m4 \
109   && $ACLOCAL --install --system-acdir ./sys-dir \
110   && diff sys-dir/my.m4 the-dir/my.m4 \
111   || r='not ok'
112
113 test_end
114
115 #---------------------------------------------------------------------------
116
117 test_begin "'-I' option wins over AC_CONFIG_MACRO_DIR"
118
119 cat > configure.ac <<'END'
120 AC_INIT([md], [4.6])
121 AC_CONFIG_MACRO_DIR([dir1])
122 MY_FOO
123 END
124
125 mkdir dir1 dir2
126 echo 'AC_DEFUN([MY_FOO], [::ko::ko::])' > dir1/1.m4
127 echo 'AC_DEFUN([MY_FOO], [::ok::ok::])' > dir2/2.m4
128
129 $ACLOCAL -I dir2 \
130   && $FGREP 'm4_include([dir2/2.m4])' aclocal.m4 \
131   && not $FGREP 'm4_include([dir1/1.m4])' aclocal.m4 \
132   && $AUTOCONF \
133   && not $FGREP '::ko::ko::' configure \
134   && $FGREP '::ok::ok::' configure \
135   || r='not ok'
136
137 test_end
138
139 #---------------------------------------------------------------------------
140
141 test_begin "AC_CONFIG_MACRO_DIR([foo]) can create directory 'foo'"
142
143 cat > configure.ac << 'END'
144 AC_INIT([x], [1.0])
145 AC_CONFIG_MACRO_DIR([foo])
146 MY_MACRO
147 END
148
149 mkdir acdir
150 echo 'AC_DEFUN([MY_MACRO], [:])' > acdir/bar.m4
151
152 test ! -d foo \
153   && $ACLOCAL --install --system-acdir ./acdir \
154   && diff acdir/bar.m4 foo/bar.m4 \
155   || r='not ok'
156
157 test_end
158
159 #---------------------------------------------------------------------------
160
161 :