* lib/autoconf/c.m4 (AC_LANG_FUNC_LINK_TRY(C)): Prefer "defined
[autoconf.git] / tests / tools.at
blobd2bbbf6043f65773e3e2bc033902b4c9d1d39a55
1 #                                                       -*- Autotest -*-
3 AT_BANNER([Executables (autoheader, autoupdate...).])
5 # Copyright (C) 2000, 2001, 2003, 2004, 2006 Free Software Foundation, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
10 # any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 # 02110-1301, USA.
23 ## ----------------------------- ##
24 ## Syntax of the shell scripts.  ##
25 ## ----------------------------- ##
27 # We use `/bin/sh -n script' to check that there are no syntax errors
28 # in the scripts.  Although incredible, there are /bin/sh that go into
29 # endless loops with `-n', e.g., SunOS's:
31 #   $ uname -a
32 #   SunOS ondine 4.1.3 2 sun4m unknown
33 #   $ cat endless.sh
34 #   while false
35 #   do
36 #     :
37 #   done
38 #   exit 0
39 #   $ time sh endless.sh
40 #   sh endless.sh  0,02s user 0,03s system 78% cpu 0,064 total
41 #   $ time sh -nx endless.sh
42 #   ^Csh -nx endless.sh  3,67s user 0,03s system 63% cpu 5,868 total
44 # So before using `/bin/sh -n' to check our scripts, we first check
45 # that `/bin/sh -n' is not broken to death.
47 AT_SETUP([Syntax of the shell scripts])
49 # Specify the absolute name of the tool, as some shells don't honor PATH when
50 # running `sh PROG'.
52 AT_CHECK_SHELL_SYNTAX([$abs_top_builddir/bin/autoconf], exit 77)
53 AT_CHECK_SHELL_SYNTAX([$abs_top_builddir/tests/autoconf], exit 77)
54 AT_CHECK_SHELL_SYNTAX([$abs_top_builddir/tests/testsuite], exit 77)
56 # These are not built, they are in the src tree.
57 AT_CHECK_SHELL_SYNTAX([$abs_top_srcdir/config/install-sh], exit 77)
58 AT_CHECK_SHELL_SYNTAX([$abs_top_srcdir/config/mkinstalldirs], exit 77)
59 AT_CHECK_SHELL_SYNTAX([$abs_top_srcdir/config/missing], exit 77)
61 AT_CLEANUP
66 ## ---------------------------- ##
67 ## Syntax of the Perl scripts.  ##
68 ## ---------------------------- ##
70 AT_SETUP([Syntax of the Perl scripts])
72 AT_CHECK_PERL_SYNTAX([autoheader])
73 AT_CHECK_PERL_SYNTAX([autom4te])
74 AT_CHECK_PERL_SYNTAX([autoreconf])
75 AT_CHECK_PERL_SYNTAX([autoscan])
76 AT_CHECK_PERL_SYNTAX([autoupdate])
77 AT_CHECK_PERL_SYNTAX([ifnames])
79 AT_CLEANUP
84 ## ------------------ ##
85 ## autom4te's cache.  ##
86 ## ------------------ ##
88 AT_SETUP([autom4te cache])
90 AT_DATA_M4SUGAR([[script.4s]],
91 [[m4_include([foo])
92 ]])
94 # Everything is OK.
95 touch foo
96 AT_CHECK_M4SUGAR
98 # We moved a file: it should fail
99 mkdir sub
100 mv foo sub
101 AT_CHECK_M4SUGAR([], [1], [],
102 [m4: script.4s: 1: Cannot open foo: No such file or directory
103 autom4te: m4 failed with exit status: 1
106 # But if we change the main file, then we should no longer complain of
107 # missing files.
108 AT_DATA_M4SUGAR([[script.4s]],
109 [[m4_include([sub/foo])
111 AT_CHECK_M4SUGAR
113 AT_CLEANUP
118 ## ------------------ ##
119 ## autoconf --trace.  ##
120 ## ------------------ ##
123 # autoconf --trace: user macros
124 # -----------------------------
125 AT_SETUP([autoconf --trace: user macros])
127 AT_DATA([configure.ac],
128 [[m4_define([active], [ACTIVE])
129 m4_define([TRACE1], [TRACE2(m4_shift($@))])
130 m4_define([TRACE2], [[$2], $1])
132 # No arguments.
133 TRACE1
134 TRACE2
136 # With arguments, single line.
137 TRACE1(foo, @bar, @baz)
138 TRACE1(foo, TRACE1(bar, baz))
139 TRACE1(foo, active, baz)
140 TRACE1(foo, [active], TRACE1(active, [active]))
142 # With arguments, multiple lines.
143 TRACE1(foo
144 bar,
146 foo)
149 # Several --traces.
150 AT_CHECK_AUTOCONF([-t TRACE1 -t TRACE2], 0,
151 [[configure.ac:6:TRACE1:
152 configure.ac:6:TRACE2:
153 configure.ac:7:TRACE2:
154 configure.ac:10:TRACE1:foo:@bar:@baz
155 configure.ac:10:TRACE2:@bar:@baz
156 configure.ac:11:TRACE1:bar:baz
157 configure.ac:11:TRACE2:baz
158 configure.ac:11:TRACE1:foo::baz
159 configure.ac:11:TRACE2::baz
160 configure.ac:12:TRACE1:foo:ACTIVE:baz
161 configure.ac:12:TRACE2:ACTIVE:baz
162 configure.ac:13:TRACE1:ACTIVE:active
163 configure.ac:13:TRACE2:active
164 configure.ac:13:TRACE1:foo:active::ACTIVE
165 configure.ac:13:TRACE2:active::ACTIVE
166 configure.ac:19:TRACE1:foo bar:bar foo
167 configure.ac:19:TRACE2:bar foo
170 # Several line requests.
171 AT_CHECK_AUTOCONF([[-t TRACE1:'
172 [$1], [$2], [$3].']], 0,
174 [], [], [].
176 [foo], [@bar], [@baz].
178 [bar], [baz], [].
180 [foo], [], [baz].
182 [foo], [ACTIVE], [baz].
184 [ACTIVE], [active], [].
186 [foo], [active], [].
188 [foo
189 bar], [bar
190 foo], [].
193 # ${sep}@.
194 AT_CHECK_AUTOCONF([-t TRACE2:'${)===(}@'], 0,
195 [[[]
197 [@bar])===([@baz]
198 [baz]
199 [])===([baz]
200 [ACTIVE])===([baz]
201 [active]
202 [active])===([])===([ACTIVE]
203 [bar
204 foo]
207 AT_CLEANUP
210 # autoconf --trace: builtins
211 # --------------------------
212 AT_SETUP([autoconf --trace: builtins])
214 AT_DATA([configure.ac],
215 [[define([active], [ACTIVE])
218 AT_CHECK_AUTOCONF([[-t define | sed -n '$p']],
219          0,
220 [[configure.ac:1:define:active:ACTIVE
223 # FIXME: Without `$1' the following test dies.  Groumphf, once again to
224 # dive into obscure feature interaction...
225 # Note that using `-i' means we need the *.m4 files, not the *.m4f files,
226 # hence we need srcdir, not builddir.
227 AT_CHECK_AUTOCONF([[-t define:'$1' -i| sed -n '$p']],
228          0,
229 [[active
232 AT_CLEANUP
236 ## ---------------------------- ##
237 ## autoconf: forbidden tokens.  ##
238 ## ---------------------------- ##
241 # autoconf: forbidden tokens, basic
242 # ---------------------------------
243 AT_SETUP([autoconf: forbidden tokens, basic])
245 AT_DATA_M4SH([configure.ac],
246 [[AS_INIT
247 m4_foo
248 _m4_bar
249 AS_FOO
250 _AS_BAR
251 [dnl]
254 AT_DATA_M4SH([experr],
255 [[configure.ac:2: error: possibly undefined macro: m4_foo
256       If this token and others are legitimate, please use m4_pattern_allow.
257       See the Autoconf documentation.
258 configure.ac:3: error: possibly undefined macro: _m4_bar
259 configure.ac:4: error: possibly undefined macro: AS_FOO
260 configure.ac:5: error: possibly undefined macro: _AS_BAR
261 configure.ac:6: error: possibly undefined macro: dnl
264 AT_CHECK_AUTOCONF([], 1, [], experr)
266 AT_CLEANUP
269 # autoconf: forbidden tokens, exceptions
270 # --------------------------------------
271 AT_SETUP([autoconf: forbidden tokens, exceptions])
273 AT_DATA_M4SH([configure.ac],
274 [[AS_INIT
276 # This is allowed in spite of the name.
277 # It is on purpose that we check the case where there are several
278 # tokens on the same line.
279 m4_pattern_allow([^AS_ALLOWED$])
280 NOT_AS_ALLOWED AS_ALLOWED AS_ALLOWED_NOT
282 # Test forbidding.
283 m4_pattern_forbid([^FORBIDDEN$])
284 NOT_FORBIDDEN FORBIDDEN FORBIDDEN_NOT
286 # Test Autoconf's patterns.
287 AS_THIS_IS_INVALID and _AS_THIS_IS_INVALID_TOO
288 BUT_AZ_THIS_IS_NOT ALTHOUGH_AS_THIS_IS
289 # This is legal, although there is `AS_DEFINE' in there.
290 BAS_DEFINE
291 # AS_THIS_IS_A_COMMENT so just shut up.
292 It would be very bad if Autoconf forgot to expand [AS_]INIT!
295 AT_DATA_M4SH([experr],
296 [[configure.ac:1: error: possibly undefined macro: AS_INIT
297       If this token and others are legitimate, please use m4_pattern_allow.
298       See the Autoconf documentation.
299 configure.ac:7: error: possibly undefined macro: AS_ALLOWED_NOT
300 configure.ac:10: error: possibly undefined macro: FORBIDDEN
301 configure.ac:14: error: possibly undefined macro: AS_THIS_IS_INVALID
302 configure.ac:14: error: possibly undefined macro: _AS_THIS_IS_INVALID_TOO
305 AT_CHECK_AUTOCONF([], 1, [], [experr])
307 AT_CLEANUP
313 ## --------- ##
314 ## ifnames.  ##
315 ## --------- ##
317 AT_SETUP([ifnames])
319 AT_DATA([iftest1.c],
320 [[#ifdef DEF1
321 #ifndef DEF2
322 #if ! defined DEF3 && defined DEF4 /* but not defined DEF5 */
323     # if SPACES
324         #       if      TABS
325 /* #if C_COMMENTS */
326 // #if CXX_COMMENTS
327 #if LINE1 = \
328 LINE2
329 #if (VAL1*VAL2)==VAL3+VAL4 /* Not VAL5 !!! */
332 AT_DATA([iftest2.c],
333 [[#ifdef IFTEST2
334 #if VAL1
337 AT_CHECK([ifnames iftest1.c iftest2.c], 0,
338 [DEF1 iftest1.c
339 DEF2 iftest1.c
340 DEF3 iftest1.c
341 DEF4 iftest1.c
342 IFTEST2 iftest2.c
343 LINE1 iftest1.c
344 LINE2 iftest1.c
345 SPACES iftest1.c
346 TABS iftest1.c
347 VAL1 iftest1.c iftest2.c
348 VAL2 iftest1.c
349 VAL3 iftest1.c
350 VAL4 iftest1.c
351 ], [])
353 AT_CLEANUP
357 ## ------------ ##
358 ## autoheader.  ##
359 ## ------------ ##
361 # autoheader is intensively used in its modern form throughout this
362 # test suite.  But we also have to check that acconfig.h still works.
363 # autoheader uses autoconf --trace, so traces first.
365 AT_SETUP([autoheader])
367 AT_DATA([acconfig.h],
368 [[/* Define this to whatever you want. */
369 #undef this
373 # 1. Check that `acconfig.h' is still honored.
374 AT_DATA([configure.ac],
375 [[AC_INIT
376 AC_CONFIG_HEADERS(config.h:config.hin)
377 AC_DEFINE(this, "whatever you want.")
380 AT_CHECK_AUTOHEADER([], [], [], [ignore])
381 AT_CHECK([cat config.hin], 0,
382 [[/* config.hin.  Generated from configure.ac by autoheader.  */
383 /* Define this to whatever you want. */
384 #undef this
386 /* Define to the address where bug reports for this package should be sent. */
387 #undef PACKAGE_BUGREPORT
389 /* Define to the full name of this package. */
390 #undef PACKAGE_NAME
392 /* Define to the full name and version of this package. */
393 #undef PACKAGE_STRING
395 /* Define to the one symbol short name of this package. */
396 #undef PACKAGE_TARNAME
398 /* Define to the version of this package. */
399 #undef PACKAGE_VERSION
403 # 2. Check that missing templates are a fatal error.
404 AT_DATA([configure.ac],
405 [[AC_INIT
406 AC_CONFIG_HEADERS(config.h:config.hin)
407 AC_DEFINE(that, "whatever you want.")
410 # The test suite goes too fast for the cache time stamps...
411 # Pass --force.
412 AT_CHECK_AUTOHEADER([--force], [1], [], [ignore])
415 # 3. Check TOP and BOTTOM.
416 AT_DATA([acconfig.h],
417 [[/* Top from acconfig.h. */
418 @TOP@
419 /* Middle from acconfig.h. */
420 @BOTTOM@
421 /* Bottom from acconfig.h. */
424 AT_DATA([configure.ac],
425 [[AC_INIT
426 AC_CONFIG_HEADERS(config.h:config.hin)
427 AH_TOP([Top1 from configure.ac.])
428 AH_TOP([Top2 from configure.ac.])
429 AH_TOP([The Cat in a h@t.])
430 AH_VERBATIM([Middle], [Middle from configure.ac.])
431 AH_VERBATIM([Mouse],  [The Mouse in a h@t.])
432 AH_BOTTOM([Bottom1 from configure.ac.])
433 AH_BOTTOM([Bottom2 from configure.ac.])
434 AH_BOTTOM([The Dog in a h@t.])
436 AC_DEFINE([ANT], [@], [The Ant in a h@t.])
440 # Yes, that's right: the `middle' part of `acconfig.h' is still before
441 # the AH_TOP part.  But so what, you're not supposed to use the two
442 # together.
443 # Ignore STDERR which is the longuish complaint against autoheader junk
444 # files.
445 AT_CHECK_AUTOHEADER([--force], [], [], [ignore])
446 AT_CHECK([cat config.hin], 0,
447 [[/* config.hin.  Generated from configure.ac by autoheader.  */
448 /* Top from acconfig.h. */
449 /* Middle from acconfig.h. */
451 Top1 from configure.ac.
453 Top2 from configure.ac.
455 The Cat in a h@t.
457 /* The Ant in a h@t. */
458 #undef ANT
460 Middle from configure.ac.
462 The Mouse in a h@t.
464 /* Define to the address where bug reports for this package should be sent. */
465 #undef PACKAGE_BUGREPORT
467 /* Define to the full name of this package. */
468 #undef PACKAGE_NAME
470 /* Define to the full name and version of this package. */
471 #undef PACKAGE_STRING
473 /* Define to the one symbol short name of this package. */
474 #undef PACKAGE_TARNAME
476 /* Define to the version of this package. */
477 #undef PACKAGE_VERSION
479 Bottom1 from configure.ac.
481 Bottom2 from configure.ac.
483 The Dog in a h@t.
484 /* Bottom from acconfig.h. */
487 AT_CLEANUP
492 ## ------------ ##
493 ## autoupdate.  ##
494 ## ------------ ##
496 # Check that AC_CANONICAL_SYSTEM and AC_OUTPUT are properly updated.
497 AT_SETUP([autoupdate])
499 AT_DATA([configure.ac],
500 [[AC_INIT(Test, 1.0)
501 AC_CANONICAL_SYSTEM
502 # The doc says 27 is a valid fubar.
503 fubar=27
504 AC_OUTPUT(Makefile, echo $fubar, fubar=$fubar)
507 AT_DATA([expout],
508 [[AC_INIT([Test],[1.0])
509 AC_CANONICAL_TARGET([])
510 # The doc says 27 is a valid fubar.
511 fubar=27
512 AC_CONFIG_FILES([Makefile])
513 AC_CONFIG_COMMANDS([default],[echo $fubar],[fubar=$fubar])
514 AC_OUTPUT
517 # Checking `autoupdate'.
518 AT_CHECK_AUTOUPDATE
519 AT_CHECK([cat configure.ac], 0, [expout])
520 # Checking that `autoupdate' is idempotent
521 AT_CHECK_AUTOUPDATE
522 AT_CHECK([cat configure.ac], 0, [expout])
524 AT_CLEANUP(configure.ac~)
527 # autoupdating AC_LINK_FILES
528 # --------------------------
529 AT_SETUP([autoupdating AC_LINK_FILES])
531 AT_DATA([configure.ac],
532 [[AC_INIT
533 AC_LINK_FILES(dst1 dst2, src1 src2)
534 AC_OUTPUT
537 AT_DATA([dst1], dst1
539 AT_DATA([dst2], dst2
542 # Checking `autoupdate'.
543 AT_CHECK_AUTOUPDATE([], 0, [], ignore)
544 AT_CHECK_AUTOCONF
545 AT_CHECK_CONFIGURE
546 AT_CHECK([cat src1], 0, [dst1
548 AT_CHECK([cat src2], 0, [dst2
551 AT_CLEANUP(src1 src2 configure.ac~)
554 # autoupdating AC_PREREQ
555 # ----------------------
556 AT_SETUP([autoupdating AC_PREREQ])
558 # Produce `AC_PREREQ(<AUTOUPDATE VERSION>)'.
559 AT_CHECK([autoupdate --version | sed 's/.*) //;q'], 0, [stdout])
560 autoupdate_version=`cat stdout`
561 echo "AC_PREREQ($autoupdate_version)" >expout
563 AT_CHECK([echo "AC_PREREQ(1.0)" | autoupdate -],
564          0, [expout], [])
566 AT_CHECK([echo "AC_PREREQ($autoupdate_version)" | autoupdate -],
567          0, [expout], [])
569 AT_CHECK([echo "AC_PREREQ(999.99)" | autoupdate -],
570          63, [], [ignore])
572 AT_CLEANUP