summaryrefslogtreecommitdiff
path: root/tests/tools.at
blob: 319bcbf19aeca9129b0eadfe4f720757b1e308e0 (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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
#							-*- autoconf -*-

AT_BANNER([Executables (autoheader, autoupdate...).])

## -------------------------------------------------------- ##
## Check that the shell scripts are syntactically correct.  ##
## -------------------------------------------------------- ##

# We use `/bin/sh -n script' to check that there are no syntax errors
# in the scripts.  Although incredible, there are /bin/sh that go into
# endless loops with `-n', e.g., SunOS's:
#
#   $ uname -a
#   SunOS ondine 4.1.3 2 sun4m unknown
#   $ cat endless.sh
#   while false
#   do
#     :
#   done
#   exit 0
#   $ time sh endless.sh
#   sh endless.sh  0,02s user 0,03s system 78% cpu 0,064 total
#   $ time sh -nx endless.sh
#   ^Csh -nx endless.sh  3,67s user 0,03s system 63% cpu 5,868 total
#
# So before using `/bin/sh -n' to check our scripts, we first check
# that `/bin/sh -n' is not broken to death.

AT_SETUP([Syntax of the scripts])

# A script that never returns.  We don't care that it never returns,
# broken /bin/sh loop equally with `false', but it makes it easier to
# test the robusteness in a good environment: just remove the `-n'.
AT_DATA(endless.sh,
[[while :
do
  :
done
]])

# A script in charge of testing `/bin/sh -n'.
AT_DATA(syntax.sh,
[[(/bin/sh -n endless.sh) &
sleep 2
if kill $! >/dev/null 2>&1; then
  # We managed to kill the child, which means that we probably
  # can't trust `/bin/sh -n', hence the test failed.
  exit 77
fi
]])

# If we can't trust sh, just skip.
AT_CHECK([/bin/sh ./syntax.sh])

# Specify the path to the tool, some shells don't honor PATH when
# running `sh PROG'.

AT_CHECK([/bin/sh -n ../autoconf],   0)
AT_CHECK([/bin/sh -n ../autoreconf], 0)
AT_CHECK([/bin/sh -n ../ifnames],    0)

# These are not built, they are in the src tree.
AT_CHECK([/bin/sh -n $at_top_srcdir/config/install-sh], 0)
AT_CHECK([/bin/sh -n $at_top_srcdir/config/mkinstalldirs], 0)
AT_CHECK([/bin/sh -n $at_top_srcdir/config/missing], 0)

AT_CLEANUP




## ----------------- ##
## AWK portability.  ##
## ----------------- ##

AT_SETUP([AWK portability])

AT_DATA([configure.ac],
[])

# Skip if we don't have GNU Awk.
AT_CHECK([gawk --version || exit 77], 0, ignore, ignore)

# Generation of the script.
AT_CHECK([AWK='gawk --posix' autoconf --autoconf-dir ../lib -l $at_srcdir], 0,
         [], [])
# Tracing.
AT_CHECK([AWK='gawk --posix' autoconf --autoconf-dir ../lib -l $at_srcdir -t AC_INIT], 0,
         ignore, [])
# Syntax correctness of ifnames.
AT_CHECK([AWK='gawk --posix' ifnames /dev/null], 0,
         [], [])

AT_CLEANUP(configure)






## ------------------ ##
## autoconf --trace.  ##
## ------------------ ##


# autoconf --trace: user macros
# -----------------------------
AT_SETUP([autoconf --trace: user macros])

AT_DATA(configure.ac,
[[m4_define([active], [ACTIVE])
m4_define([TRACE1], [TRACE2(m4_shift($@))])
m4_define([TRACE2], [[$2], $1])
TRACE1(foo, bar, baz)
TRACE1(foo, TRACE1(bar, baz))
TRACE1(foo, active, baz)
TRACE1(foo, [active], TRACE1(active, [active]))
]])

# Several --traces.
AT_CHECK([autoconf --autoconf-dir ../lib -l $at_srcdir -t TRACE1 -t TRACE2], 0,
[[configure.ac:4:TRACE1:foo:bar:baz
configure.ac:4:TRACE2:bar:baz
configure.ac:5:TRACE1:bar:baz
configure.ac:5:TRACE2:baz
configure.ac:5:TRACE1:foo::baz
configure.ac:5:TRACE2::baz
configure.ac:6:TRACE1:foo:ACTIVE:baz
configure.ac:6:TRACE2:ACTIVE:baz
configure.ac:7:TRACE1:ACTIVE:active
configure.ac:7:TRACE2:active
configure.ac:7:TRACE1:foo:active::ACTIVE
configure.ac:7:TRACE2:active::ACTIVE
]])

# Several line requests.
AT_CHECK([[autoconf --autoconf-dir ../lib -l $at_srcdir -t TRACE1:'
[$1], [$2], [$3].']], 0,
[[
[foo], [bar], [baz].

[bar], [baz], [].

[foo], [], [baz].

[foo], [ACTIVE], [baz].

[ACTIVE], [active], [].

[foo], [active], [].
]])

# ${sep}@.
AT_CHECK([autoconf --autoconf-dir ../lib -l $at_srcdir -t TRACE2:'${)===(}@'], 0,
[[[bar])===([baz]
[baz]
[])===([baz]
[ACTIVE])===([baz]
[active]
[active])===([])===([ACTIVE]
]])

AT_CLEANUP


# autoconf --trace: builtins
# --------------------------
AT_SETUP([autoconf --trace: builtins])

AT_DATA(configure.ac,
[[define([active], [ACTIVE])
]])

AT_CHECK([[autoconf --autoconf-dir ../lib -l $at_srcdir -t define |
            sed -n '$p']],
         0,
[[configure.ac:1:define:active:ACTIVE
]])

# FIXME: Without `$1' the following test dies.  Groumphf, once again to
# dive into obscure feature interaction...
# Note that using `-i' means we need the *.m4 files, not the *.m4f files,
# hence we need srcdir, not builddir.
AT_CHECK([[autoconf --autoconf-dir $at_top_srcdir/lib -l $at_srcdir -t define:'$1' -i|
            sed -n '$p']],
         0,
[[active
]])

AT_CLEANUP




## ---------------------------- ##
## autoconf: forbidden tokens.  ##
## ---------------------------- ##

# autoconf: forbidden tokens, basic
# ---------------------------------
AT_SETUP([autoconf: forbidden tokens, basic])

AT_DATA([configure.ac],
[[AC_PLAIN_SCRIPT()dnl
AC_FOO
_AC_BAR
m4_foo
_m4_bar
BAC_FOO
B_AC_FOO
AS_FOO
_AS_BAR
]])

AT_CHECK([autoconf --autoconf-dir ../lib -l $at_srcdir], 1, [], [stderr])
# The output of autoconf is not deterministic here because it
# uses `for (ind in array)'.  So be sure to have a unique representation.
AT_CHECK([sort stderr], 0,
[[configure.ac:2: error: possibly undefined macro: AC_FOO
configure.ac:3: error: possibly undefined macro: _AC_BAR
configure.ac:4: error: possibly undefined macro: m4_foo
configure.ac:7: error: possibly undefined macro: B_AC_FOO
configure.ac:8: error: possibly undefined macro: AS_FOO
configure.ac:9: error: possibly undefined macro: _AS_BAR
]])

AT_CLEANUP(configure)


# autoconf: forbidden tokens, exceptions
# --------------------------------------
AT_SETUP([autoconf: forbidden tokens, exceptions])

AT_DATA([configure.ac],
[[AC_PLAIN_SCRIPT()dnl

# This is allowed in spite of the name.
# It is on purpose that we check the case where there are several
# tokens on the same line.
m4_pattern_allow([^AC_ALLOWED$])
NOT_AC_ALLOWED AC_ALLOWED AC_ALLOWED_NOT

# Test forbidding.
m4_pattern_forbid([^FORBIDDEN$])
NOT_FORBIDDEN FORBIDDEN FORBIDDEN_NOT

# Test Autoconf's patterns.
AC_THIS_IS_INVALID and _AC_THIS_IS_INVALID_TOO
BUT_AZ_THIS_IS_NOT ALTHOUGH_AC_THIS_IS
# This is legal, although there is `AC_DEFINE' in there.
BAC_DEFINE
# AC_THIS_IS_A_COMMENT so just shut up.
It would be very bad if Autoconf forgot to expand [AC_]OUTPUT!
]])

AT_CHECK([autoconf --autoconf-dir ../lib -l $at_srcdir], 1, [], [stderr])
# The output of autoconf is not deterministic here because it
# uses `for (ind in array)'.  So be sure to have a unique representation.
AT_CHECK([sort stderr], 0,
[[configure.ac:10: error: possibly undefined macro: FORBIDDEN
configure.ac:14: error: possibly undefined macro: AC_THIS_IS_INVALID
configure.ac:14: error: possibly undefined macro: _AC_THIS_IS_INVALID_TOO
configure.ac:15: error: possibly undefined macro: ALTHOUGH_AC_THIS_IS
configure.ac:7: error: possibly undefined macro: AC_ALLOWED_NOT
configure.ac:7: error: possibly undefined macro: NOT_AC_ALLOWED
configure:18: error: possibly undefined macro: AC_OUTPUT
]])

AT_CLEANUP(configure err)





## --------- ##
## ifnames.  ##
## --------- ##

AT_SETUP([ifnames])

AT_DATA([iftest1.c],
[[#ifdef DEF1
#ifndef DEF2
#if !defined(DEF3) && defined(DEF4) /* but not defined(DEF5) */
    # if SPACES
	#	if	TABS
/* #if C_COMMENTS */
// #if CXX_COMMENTS
#if LINE1 = \
LINE2
#if (VAL1*VAL2)==VAL3+VAL4 /* Not VAL5 !!! */
]])

AT_DATA([iftest2.c],
[[#ifdef IFTEST2
#if VAL1
]])

AT_CHECK([ifnames iftest1.c iftest2.c], 0,
[DEF1 iftest1.c
DEF2 iftest1.c
DEF3 iftest1.c
DEF4 iftest1.c
IFTEST2 iftest2.c
LINE1 iftest1.c
LINE2 iftest1.c
SPACES iftest1.c
TABS iftest1.c
VAL1 iftest1.c iftest2.c
VAL2 iftest1.c
VAL3 iftest1.c
VAL4 iftest1.c
], [])

AT_CLEANUP



## ------------ ##
## autoheader.  ##
## ------------ ##

# autoheader is intensively used in its modern form throught this
# test suite.  But we also have to check that acconfig.h still works.
# autoheader uses autoconf --trace, so traces first.

AT_SETUP([autoheader])

AT_DATA(acconfig.h,
[[/* Define this to whatever you want. */
#undef this
]])


# 1. Check that `acconfig.h' is still honored.
AT_DATA(configure.ac,
[[AC_INIT
AC_CONFIG_HEADERS(config.h)
AC_DEFINE(this, "whatever you want.")
]])

AT_CHECK([autoheader --autoconf-dir ../lib -<configure.ac], 0,
[[/* config.h.in.  Generated automatically from Standard input by autoheader.  */
/* Define this to whatever you want. */
#undef this
]], ignore)


# 2. Check that missing templates are a fatal error.
AT_DATA(configure.ac,
[[AC_INIT
AC_CONFIG_HEADERS(config.h)
AC_DEFINE(that, "whatever you want.")
]])

AT_CHECK([autoheader --autoconf-dir ../lib -<configure.ac], 1, [],
[autoheader: No template for symbol `that'
])


# 3. Check TOP and BOTTOM.
AT_DATA(acconfig.h,
[[/* Top from acconfig.h. */
@TOP@
/* Middle from acconfig.h. */
@BOTTOM@
/* Bottom from acconfig.h. */
]])

AT_DATA(configure.ac,
[[AC_INIT
AC_CONFIG_HEADERS(config.h)
AH_TOP([Top1 from configure.ac.])
AH_TOP([Top2 from configure.ac.])
AH_VERBATIM([Middle], [Middle from configure.ac.])
AH_BOTTOM([Bottom1 from configure.ac.])
AH_BOTTOM([Bottom2 from configure.ac.])
]])


# Yes, that's right: the `middle' part of `acconfig.h' is still before
# the AH_TOP part.  But so what, you're not supposed to use the two
# together.
AT_CHECK([autoheader --autoconf-dir ../lib -<configure.ac], 0,
[[/* config.h.in.  Generated automatically from Standard input by autoheader.  */
/* Top from acconfig.h. */

/* Middle from acconfig.h. */

Top1 from configure.ac.

Top2 from configure.ac.

Middle from configure.ac.

Bottom1 from configure.ac.

Bottom2 from configure.ac.
/* Bottom from acconfig.h. */
]], [])


AT_CLEANUP




## ------------ ##
## autoupdate.  ##
## ------------ ##

# Check that AC_CANONICAL_SYSTEM and AC_OUTPUT are properly updated.
AT_SETUP([autoupdate])

AT_DATA(configure.ac,
[[AC_INIT(Test, 1.0)
AC_CANONICAL_SYSTEM
dnl The doc says 27 is a valid fubar.
fubar=27
AC_OUTPUT(Makefile, echo $fubar, fubar=$fubar)
]])

AT_DATA([expout],
[[AC_INIT([Test],[1.0])
AC_CANONICAL_TARGET([])
dnl The doc says 27 is a valid fubar.
fubar=27
AC_CONFIG_FILES([Makefile])
AC_CONFIG_COMMANDS([default],[[echo $fubar]],[[fubar=$fubar]])
AC_OUTPUT
]])

# Checking `autoupdate'.
AT_CHECK_AUTOUPDATE
AT_CHECK([cat configure.ac], 0, [expout])
# Checking that `autoupdate' is idempotent
AT_CHECK([autoupdate --autoconf-dir $at_top_srcdir/lib], 0, [],
         [autoupdate: `configure.ac' is unchanged
])
AT_CHECK([cat configure.ac], 0, [expout])

AT_CLEANUP(configure.ac~)


# autoupdating AC_LINK_FILES
# --------------------------
AT_SETUP([autoupdating AC_LINK_FILES])

AT_DATA(configure.ac,
[[AC_INIT
AC_LINK_FILES(dst1 dst2, src1 src2)
AC_OUTPUT
]])

AT_DATA(dst1, dst1
)
AT_DATA(dst2, dst2
)

# Checking `autoupdate'.
AT_CHECK_AUTOUPDATE
AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE
AT_CHECK([cat src1], 0, [dst1
])
AT_CHECK([cat src2], 0, [dst2
])

AT_CLEANUP(src1 src2 configure.ac~)


# autoupdating AC_PREREQ
# ----------------------
AT_SETUP([autoupdating AC_PREREQ])

cat >expout <<EOF
AC_PREREQ($at_version)
EOF

AT_CHECK([autoupdate --version || exit 77], ignore, ignore, ignore)
AT_CHECK([echo "AC_PREREQ(1.0)" |
            autoupdate --autoconf-dir $at_top_srcdir/lib -],
         0, [expout], [])

AT_CHECK([echo "AC_PREREQ($at_version)" |
            autoupdate --autoconf-dir $at_top_srcdir/lib -],
         0, [expout], [])

AT_CHECK([echo "AC_PREREQ(999.99)" |
            autoupdate --autoconf-dir $at_top_srcdir/lib -],
         1, [], [ignore])

AT_CLEANUP