summaryrefslogtreecommitdiff
path: root/tests/base.at
blob: 5ce3e89084a687aa3f3fa3d2ed69af13541f21d0 (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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
#							-*- Autotest -*-

AT_BANNER([Autoconf base layer.])

# Copyright (C) 2000, 2001, 2003, 2005, 2006, 2007, 2008, 2009, 2010
# 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 3 of the License, 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/>.


## ------------------------------- ##
## AC_REQUIRE: topological sort..  ##
## ------------------------------- ##

# Check that dependencies are always properly honored.

AT_SETUP([AC_REQUIRE: topological sort])
AT_KEYWORDS([m4@&t@_require])

AT_DATA([configure.ac],
[[define([REQUIRE_AND_CHECK],
[AC_REQUIRE([$1])
test -z "$m4@&t@_translit([$1], [A-Z], [a-z])" && AS_EXIT(1)])

AC_DEFUN([TEST1],
[REQUIRE_AND_CHECK([TEST2a])
REQUIRE_AND_CHECK([TEST2b])
test1=set])

AC_DEFUN([TEST2a],
[test2a=set])

AC_DEFUN([TEST2b],
[REQUIRE_AND_CHECK([TEST3])
test2b=set])

AC_DEFUN([TEST3],
[REQUIRE_AND_CHECK([TEST2a])
test3=set])

AS@&t@_INIT

TEST1
test -z "$test1" &&
  AC_MSG_ERROR([\$test1 is empty])
AS_EXIT(0)
]])

AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE

AT_CLEANUP


## --------------------------- ##
## AC_REQUIRE: error message.  ##
## --------------------------- ##

# Check that the message mentions AC_DEFUN, not m4_defun.

AT_SETUP([AC_REQUIRE: error message])
AT_KEYWORDS([m4@&t@_require])
AT_DATA([configure.ac],
[[AC_REQUIRE([AC_PROG_CC])
]])

AT_CHECK_AUTOCONF([], [1], [],
[[configure.ac:1: error: AC_REQUIRE(AC_PROG_CC): cannot be used outside of an AC_DEFUN'd macro
configure.ac:1: the top level
autom4te: m4 failed with exit status: 1
]])
AT_CLEANUP


## ----------------------------------------------- ##
## AC_REQUIRE and AC_DEFUN_ONCE: Require, expand.  ##
## ----------------------------------------------- ##

AT_SETUP([AC_REQUIRE & AC_DEFUN_ONCE: [Require, expand]])
AT_KEYWORDS([m4@&t@_require m4@&t@_require_once])

AT_DATA([configure.ac],
[[AC_DEFUN([TEST],
[AC_REQUIRE([MULTI_TEST])
AC_REQUIRE([SINGLE_TEST])])

AC_DEFUN([MULTI_TEST],
[multi_test=".$multi_test"])

AC_DEFUN_ONCE([SINGLE_TEST],
[single_test=".$single_test"])

AS@&t@_INIT

TEST
TEST
MULTI_TEST
MULTI_TEST
SINGLE_TEST
SINGLE_TEST

case $multi_test:$single_test in
  ...:. ) AS_EXIT(0);;
  ...:* ) AC_MSG_ERROR([DEFUN_ONCE is broken]);;
  *:.   ) AC_MSG_ERROR([DEFUN is broken (Wow, congrats!)]);;
esac
]])

AT_CHECK_AUTOCONF([], 0, [])

AT_CHECK_CONFIGURE

AT_CLEANUP



## ----------------------------------------------- ##
## AC_REQUIRE and AC_DEFUN_ONCE: Expand, require.  ##
## ----------------------------------------------- ##

AT_SETUP([AC_REQUIRE & AC_DEFUN_ONCE: [Expand, require]])
AT_KEYWORDS([m4@&t@_require m4@&t@_require_once])

AT_DATA([configure.ac],
[[AC_DEFUN([TEST],
[AC_REQUIRE([MULTI_TEST])
AC_REQUIRE([SINGLE_TEST])])

AC_DEFUN([MULTI_TEST],
[multi_test=".$multi_test"])

AC_DEFUN_ONCE([SINGLE_TEST],
[single_test=".$single_test"])

AS@&t@_INIT

MULTI_TEST
MULTI_TEST
SINGLE_TEST
SINGLE_TEST
TEST
TEST

case $multi_test:$single_test in
  ..:. ) AS_EXIT(0);;
  ..:* ) AC_MSG_ERROR([DEFUN_ONCE is broken]);;
  *:.  ) AC_MSG_ERROR([DEFUN is broken (Wow, congrats!)]);;
     * ) AC_MSG_ERROR([received `$multi_test:$single_test']);;
esac
]])

AT_CHECK_AUTOCONF([], 0, [])
AT_CHECK_CONFIGURE

AT_CLEANUP



## ------------------------- ##
## AC_REQUIRE & AC_PROVIDE.  ##
## ------------------------- ##

AT_SETUP([AC_REQUIRE & AC_PROVIDE])
AT_KEYWORDS([m4@&t@_require])

AT_DATA([configure.ac],
[[AC_DEFUN([TEST],
[AC_REQUIRE([INNER_TEST])])

AC_DEFUN([INNER_TEST],
[inner_test=".$inner_test"])

AS@&t@_INIT

AC_PROVIDE([INNER_TEST])
TEST

case $inner_test in
  "" ) AS_EXIT(0);;
  *  ) AC_MSG_ERROR([received `$inner_test']);;
esac
]])

AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE

AT_CLEANUP


## -------- ##
## AC_INIT. ##
## -------- ##

# Make sure AC_INIT sets PACKAGE_TARNAME properly.

AT_SETUP([AC_INIT])

AT_DATA([configure.ac],
[[AC_INIT([GNU fu], [1.0], [bug-fu@gnu.org])
]])

AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE([-q])

# Ensure we get the expected definition:
AT_CHECK([grep "^PACKAGE_TARNAME='fu'\$" configure], [], [ignore])

AT_CLEANUP


## ---------------- ##
## AC_CACHE_CHECK.  ##
## ---------------- ##

# Make sure AC_CACHE_CHECK is silent with -q.
# Also make sure we warn about cache id's not named with `_cv_'.

AT_SETUP([AC_CACHE_CHECK])

AT_DATA([configure.ac],
[[AC_INIT
# m4_define([ac_nothing], [ac_cv_absolutely_nothing])
AC_CACHE_CHECK([for nothing],
	       [ac_nothing],
	       [ac_nothing=found])
]])

AT_CHECK_AUTOCONF([], [], [], [stderr])
AT_CHECK([grep 'must contain _cv_ to be cached' stderr], [], [ignore])

# Do not warn about defines:
sed 's/^# //' configure.ac > t
mv -f t configure.ac
AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE([-q])

sed '/m4_define/d; s/ac_nothing/ac_cv_nothing/' configure.ac > t
mv -f t configure.ac
AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE([-q])

AT_CLEANUP


## ---------------- ##
## AC_COMPUTE_INT.  ##
## ---------------- ##

# Make sure AC_COMPUTE_INT fails properly.

AT_SETUP([AC_COMPUTE_INT])

AT_DATA([configure.ac],
[[AC_INIT
AC_COMPUTE_INT([invalid_expression],
	       [**0**],
	       [],
	       [invalid_expression=failed])
test "$invalid_expression" = failed ||
  AC_MSG_ERROR([**0** evaluated to $invalid_expression instead of failing])
]])

AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE

AT_CLEANUP


## ---------------- ##
## AC_TRY_COMMAND.  ##
## ---------------- ##

AT_SETUP([AC_TRY_COMMAND])

AT_DATA([configure.ac],
[[AC_INIT

if AC_TRY_COMMAND([(echo "The Cat in the Hat";
		    echo "The Hat in the Cat" >&2) |
		   grep \^The\ Cat\ in\ the\ Hat\$ >/dev/null]); then
  :
else
  AC_MSG_ERROR([Didn't see the Cat in the Hat!])
fi

if AC_TRY_COMMAND([(echo "The Cat in the Hat";
		    echo "The Hat in the Cat" >&2) |
		   grep \^The\ Hat\ in\ the\ Cat\$ >/dev/null]); then
  AC_MSG_ERROR([Saw the Hat in the Cat!])
fi
]])

AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE([-q])

AT_CLEANUP


## ------------ ##
## Input/Output ##
## ------------ ##

AT_SETUP([Input/Output])

AT_DATA([configure.ac],
[[AC_INIT
cat <&AS@&t@_ORIGINAL_STDIN_FD >&AS@&t@_MESSAGE_FD
]])
AT_CHECK_AUTOCONF
AT_CHECK([echo Hello | CONFIG_SITE=/dev/null ./configure $configure_options | grep -v 'configure: loading site script '],, [Hello
])
AT_CHECK([echo Hello | CONFIG_SITE=/dev/null ./configure $configure_options --silent])

AT_CLEANUP


## ------------------- ##
## configure arguments ##
## ------------------- ##

AT_SETUP([configure arguments])

AT_DATA([configure.ac],
[[AC_INIT
echo "$@"
]])

AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE([FOO=bar --enable-baz --without-zork --silent], [0], [stdout], [ignore])
AT_CHECK([grep 'FOO=bar --enable-baz --without-zork --silent' stdout], [0], [ignore], [ignore])

dnl check that syntax error is detected
AT_CHECK_CONFIGURE([=], [1], [], [ignore], [ignore])
AT_CHECK_CONFIGURE([1=2], [1], [], [ignore], [ignore])

AT_CLEANUP


## --------------------- ##
## configure directories ##
## --------------------- ##

AT_SETUP([configure directories])

AT_DATA([foo.in],
[[prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
]])

AT_DATA([configure.ac],
[[AC_INIT
AC_CONFIG_FILES([foo])
AC_OUTPUT
]])

AT_CHECK_AUTOCONF
dnl check that relative paths are rejected
AT_CHECK_CONFIGURE([--libdir=.], [1], [ignore], [stderr])
AT_CHECK([grep 'expected an absolute directory name for --libdir: \.' stderr],
	 [0], [ignore])

dnl check that extra slashes are stripped, and that defaults are not expanded
AT_CHECK_CONFIGURE([--prefix=/usr//])
AT_CHECK([cat foo], [0], [[prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
]])

AT_CLEANUP