summaryrefslogtreecommitdiff
path: root/t/aclocal-macrodirs.tap
blob: 2440d8f3f959f90ea15a080ef3df505356e60c55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#! /bin/sh
# Copyright (C) 2012 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Several tests on the use of the m4 macro AC_CONFIG_MACRO_DIRS with
# aclocal.  See also related test 'aclocal-macrodir.tap'.

am_create_testdir=empty
. test-init.sh

{ $AUTOCONF -o /dev/null - <<END
    AC_INIT([x], [0])
    AC_CONFIG_MACRO_DIRS([.])
END
} || skip_all_ "autoconf doesn't define the AC_CONFIG_MACRO_DIRS macro"

plan_ 11

ocwd=$(pwd) || fatal_ "getting current working directory"
ACLOCAL_PATH=; unset ACLOCAL_PATH

#
# General utility functions and variables.
#
# TODO: These should maybe be refactored, generalized and
#       moved into 't/ax/tap-functions.sh' ...
#

tcount=0
r=invalid
description=''
directive=''

test_begin ()
{
  if test -n "$description"; then
    fatal_ "'test_begin' called, but another test seems active already"
  else
    r=ok
    description=$1
    directive=${2-}
    echo "$description" > README.txt
    shift
  fi
  tcount=$(($tcount + 1)) && test $tcount -gt 0 \
    || fatal_ "failed to bump the test count"
  mkdir $tcount.d
  cd $tcount.d
}

test_end ()
{
  if test -z "$description"; then
    fatal_ "'test_end' called, but no test seems active"
  else
    cd "$ocwd" || fatal_ "cannot chdir back to top-level directory"
    result_ "$r" -D "$directive" -- "$description"
    # Don't leave directories for successful subtests hanging around.
    if test -z "$directive" && test "$r" = ok; then
      rm -rf "$tcount.d" || fatal_ "removing subdir $tcount.d"
    fi
    r=invalid directive= description=
  fi
}

#---------------------------------------------------------------------------

test_begin "AC_CONFIG_MACRO_DIRS is honored"

cat > configure.ac <<'END'
AC_INIT([md], [10.0])
AC_CONFIG_MACRO_DIRS([macro-dir])
MY_FOO
END

mkdir macro-dir
echo 'AC_DEFUN([MY_FOO], [::my::foo::])' > macro-dir/foo.m4

$ACLOCAL \
  && $FGREP 'm4_include([macro-dir/foo.m4])' aclocal.m4 \
  && $AUTOCONF \
  && not $FGREP 'MY_FOO' configure \
  && $FGREP '::my::foo::' configure \
  || r='not ok'

test_end

#---------------------------------------------------------------------------

two_dirs_check ()
{
  mkdir dir1 dir2
  echo 'AC_DEFUN([MY_FOO], [::my::foo::])' > dir1/foo.m4
  echo 'AC_DEFUN([MY_BAR], [!!my!!bar!!])' > dir2/zap.m4
  $ACLOCAL \
    && $FGREP 'm4_include([dir1/foo.m4])' aclocal.m4 \
    && $FGREP 'm4_include([dir2/zap.m4])' aclocal.m4 \
    && $AUTOCONF \
    && not $EGREP 'MY_(FOO|BAR)' configure \
    && $FGREP '::my::foo::' configure \
    && $FGREP '!!my!!bar!!' configure \
    || r='not ok'
}

#---------------------------------------------------------------------------

test_begin "AC_CONFIG_MACRO_DIRS: several arguments"

cat > configure.ac <<'END'
AC_INIT([more-args], [0.2])
AC_CONFIG_MACRO_DIRS([dir1 dir2])
MY_FOO
MY_BAR
END

two_dirs_check

test_end

#---------------------------------------------------------------------------

test_begin "AC_CONFIG_MACRO_DIRS: several calls"

cat > configure.ac <<'END'
AC_INIT([more-calls], [2.0])
AC_CONFIG_MACRO_DIRS([dir1])
AC_CONFIG_MACRO_DIRS([dir2])
MY_FOO
MY_BAR
END

two_dirs_check

test_end

#---------------------------------------------------------------------------

test_begin "AC_CONFIG_MACRO_DIRS interaction with --install"

cat > configure.ac << 'END'
AC_INIT([inst], [1.0])
AC_CONFIG_MACRO_DIRS([the-dir])
THE_MACRO
END

mkdir sys-dir the-dir
echo 'AC_DEFUN([THE_MACRO], [:])' > sys-dir/my.m4

test ! -r the-dir/my.m4 \
  && $ACLOCAL --install --system-acdir ./sys-dir \
  && diff sys-dir/my.m4 the-dir/my.m4 \
  || r='not ok'

test_end

#---------------------------------------------------------------------------

two_dirs_install_check ()
{
  mkdir sys-dir dir1 dir2
  echo 'AC_DEFUN([THE_MACRO], [:])' > sys-dir/my.m4
  echo 'AC_DEFUN([AX_FOO], [:])' > dir2/zap.m4
  test ! -r dir1/my.m4 \
    && $ACLOCAL --install --system-acdir ./sys-dir \
    && diff sys-dir/my.m4 dir1/my.m4 \
    && test ! -e dir2/my.m4 \
    && $FGREP 'm4_include([dir1/my.m4])' aclocal.m4 \
    && $FGREP 'm4_include([dir2/zap.m4])' aclocal.m4 \
    || r='not ok'
}

#---------------------------------------------------------------------------

test_begin "several AC_CONFIG_MACRO_DIRS arguments and --install"

cat > configure.ac << 'END'
AC_INIT([inst2a], [1.0])
AC_CONFIG_MACRO_DIRS([dir1 dir2])
THE_MACRO
AX_FOO
END

two_dirs_install_check

test_end

#---------------------------------------------------------------------------


test_begin "several AC_CONFIG_MACRO_DIRS calls and --install"

cat > configure.ac << 'END'
AC_INIT([inst2b], [1.0])
AC_CONFIG_MACRO_DIRS([dir1])
AC_CONFIG_MACRO_DIRS([dir2])
THE_MACRO
AX_FOO
END

two_dirs_install_check

test_end

#---------------------------------------------------------------------------

test_begin "'-I' option wins over AC_CONFIG_MACRO_DIRS"

cat > configure.ac <<'END'
AC_INIT([md], [4.6])
AC_CONFIG_MACRO_DIRS([dir1])
MY_FOO
END

mkdir dir1 dir2
echo 'AC_DEFUN([MY_FOO], [::ko::ko::])' > dir1/1.m4
echo 'AC_DEFUN([MY_FOO], [::ok::ok::])' > dir2/2.m4

$ACLOCAL -I dir2 \
  && $FGREP 'm4_include([dir2/2.m4])' aclocal.m4 \
  && not $FGREP 'm4_include([dir1/1.m4])' aclocal.m4 \
  && $AUTOCONF \
  && not $FGREP '::ko::ko::' configure \
  && $FGREP '::ok::ok::' configure \
  || r='not ok'

test_end

#---------------------------------------------------------------------------

test_begin "AC_CONFIG_MACRO_DIRS([foo]) can create directory 'foo'"

cat > configure.ac << 'END'
AC_INIT([x], [1.0])
AC_CONFIG_MACRO_DIRS([foo])
MY_MACRO
END

mkdir acdir
echo 'AC_DEFUN([MY_MACRO], [:])' > acdir/bar.m4

test ! -d foo \
  && $ACLOCAL --install --system-acdir ./acdir \
  && diff acdir/bar.m4 foo/bar.m4 \
  || r='not ok'

test_end

#---------------------------------------------------------------------------

test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) errors out (1)"

cat > configure.ac << 'END'
AC_INIT([oops], [1.0])
AC_CONFIG_MACRO_DIRS([non-existent])
END

not $ACLOCAL 2>stderr \
  && cat stderr >&2 \
  && grep "couldn't open directory 'non-existent'" stderr \
  || r='not ok'

test_end

#---------------------------------------------------------------------------

test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) errors out (2)"

cat > configure.ac << 'END'
AC_INIT([oops], [1.0])
AC_CONFIG_MACRO_DIRS([dir-ok])
AC_CONFIG_MACRO_DIRS([dir-ko])
END

mkdir dir-ok
not $ACLOCAL 2>stderr \
  && cat stderr >&2 \
  && grep "couldn't open directory 'dir-ko'" stderr \
  && not grep "dir-ok" stderr \
  || r='not ok'

test_end

#---------------------------------------------------------------------------

test_begin "AC_CONFIG_MACRO_DIRS([non-existent]) errors out (tricky setup)"

cat > configure.ac << 'END'
AC_INIT([oops], [1.0])
AC_CONFIG_MACRO_DIRS([dir-ok])
AC_CONFIG_MACRO_DIRS([dir-ko])
END

mkdir dir-ok

not $ACLOCAL -Wnone --install 2>stderr \
  && cat stderr >&2 \
  && grep "couldn't open directory 'dir-ko'" stderr \
  && test ! -e dir-ko \
  || r='not ok'

test_end

#---------------------------------------------------------------------------

: