* lib/autoconf/programs.m4 (AC_PROG_SED): New macro to test for a
[autoconf.git] / tests / torture.at
blobd8807de3219652add8fce4c9667c97ec520bd73c
1 #                                                       -*- Autotest -*-
3 # Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
8 # any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 # 02111-1307, USA.
21 AT_BANNER([[Testing config.status.]])
24 ## ---------------------------------------- ##
25 ## AC_CONFIG_COMMANDS with empty commands.  ##
26 ## ---------------------------------------- ##
28 AT_CHECK_MACRO([AC_CONFIG_COMMANDS with empty commands],
29 [[AC_CONFIG_COMMANDS([foo], [], [:])
30 ]])
33 ## -------------------------- ##
34 ## Multiple AC_CONFIG_FILES.  ##
35 ## -------------------------- ##
37 AT_SETUP([Multiple AC_CONFIG_FILES])
39 AT_CONFIGURE_AC([[AC_CONFIG_FILES([foo foo])]])
40 AT_CHECK_AUTOCONF([], 1, [], [ignore])
42 AT_CLEANUP
46 ## ------------ ##
47 ## AC_ARG_VAR.  ##
48 ## ------------ ##
50 # AT_CHECK_AC_ARG_VAR(FIRST-VALUE, SECOND-VALUE)
51 # ----------------------------------------------
52 # Check that AC_ARG_VAR caches the latest values, diagnoses
53 # inconsistencies, and arms config.status.
54 m4_define([AT_CHECK_AC_ARG_VAR],
55 [rm -f config.cache
57 # Initial value.
58 m4_ifval([$1],
59          [precious='$1'; export precious],
60          [unset precious])
61 AT_CHECK_CONFIGURE([--config-cache -q])
62 AT_CHECK([cat file], [], [`$1'
65 # Testing --recheck: 1. have the environment `forget' about PRECIOUS.
66 unset precious
67 # 2. Rerun config.status to recreate `file'.
68 AT_CHECK([./config.status --recheck], [], [ignore])
69 AT_CHECK([./config.status], [], [ignore])
70 # 3. Check that file contains the old value of PRECIOUS.
71 AT_CHECK([cat file], [], [`$1'
74 # Second value: we should issue an error here: the value
75 # has changed!
76 m4_ifval([$2],
77          [precious='$2'; export precious],
78          [unset precious])
79 AT_CHECK_CONFIGURE([--config-cache], [1], [], [ignore])
81 ])# AT_CHECK_AC_ARG_VAR
84 AT_SETUP([AC_ARG_VAR])
86 # We don't want to run this test if this shell doesn't support
87 # `unset'.
88 AT_CHECK([
89 if (FOO=FOO; unset FOO) >/dev/null 2>&1; then
90   exit 0
91 else
92   exit 77
96 AT_DATA([configure.ac],
97 [[AC_INIT
98 AC_ARG_VAR([precious], [this variable costs a lot])
99 echo "precious:$precious"
100 AC_OUTPUT(file)
103 AT_DATA([file.in],
104 [[`@precious@'
107 AT_CHECK_AUTOCONF
109 # Set a precious variable
110 AT_CHECK_AC_ARG_VAR([], [apple of my eye])
112 # Unset a precious variable
113 AT_CHECK_AC_ARG_VAR([apple of my eye], [])
115 # Change a precious variable
116 AT_CHECK_AC_ARG_VAR([apple of my eye], [orange of my eye])
118 AT_CLEANUP
123 ## ---------------------------------------------- ##
124 ## AC_CONFIG_FILES, HEADERS, LINKS and COMMANDS.  ##
125 ## ---------------------------------------------- ##
127 AT_SETUP([AC_CONFIG_FILES, HEADERS, LINKS and COMMANDS])
129 AT_DATA([configure.ac],
130 [[AC_INIT
131 rm -f -r header var-header file var-file link var-link command var-command
132 echo 'OK' >input
134 # Be sure to also stress the associated INIT-CMDS.
135 case $what_to_test in
136  header)
137    AC_CONFIG_HEADERS(header:input);;
138  var-header)
139    AC_CONFIG_HEADERS(var-header:$header_in, [], [header_in=input]);;
141  file)
142    AC_CONFIG_FILES(file:input);;
143  var-file)
144    AC_CONFIG_FILES(var-file:$file_in, [], [file_in=input]);;
146  command)
147    AC_CONFIG_COMMANDS(command:input,
148                       [cp input command]);;
149  var-command)
150    AC_CONFIG_COMMANDS(var-command:$command_in,
151                       [cp $command_in var-command], [command_in=input]);;
153  link)
154    AC_CONFIG_LINKS(link:input);;
155  var-link)
156    AC_CONFIG_LINKS(var-link:$link_in, [], [link_in=input]);;
157 esac
158 AC_OUTPUT
161 AT_CHECK_AUTOCONF
164 # AT_CHECK_CONFIG_CREATION(THING = (header | link | file | command))
165 # ------------------------------------------------------------------
166 # Check that THING and var-THING (which uses variables in AC_CONFIG_THING)
167 # are properly created, with the right content.
168 # Use `grep OK' instead of a simple `cat' to avoid banners such as in
169 # AC_CONFIG_HEADERS.
170 m4_define([AT_CHECK_CONFIG_CREATION],
171 [AT_CHECK_CONFIGURE([what_to_test=$1])
172 AT_CHECK([ls header var-header file var-file command var-command link var-link 2>/dev/null],
173          [ignore], [$1
175 AT_CHECK([grep OK $1], [], [OK
178 AT_CHECK_CONFIGURE([what_to_test=var-$1 --no-create])
179 # config.status might be stupidly expecting data on stdin, if it's
180 # really broken...
181 AT_CHECK([./config.status var-$1 </dev/null], [], [ignore])
182 AT_CHECK([ls header var-header file var-file command var-command link var-link 2>/dev/null],
183          [ignore], [var-$1
185 AT_CHECK([grep OK var-$1], [], [OK
187 ])# AT_CHECK_CONFIG_CREATION
190 # Create a file
191 AT_CHECK_CONFIG_CREATION(file)
193 # Create a header
194 AT_CHECK_CONFIG_CREATION(header)
196 # Execute a command
197 AT_CHECK_CONFIG_CREATION(command)
199 # Create a link
200 AT_CHECK_CONFIG_CREATION(link)
202 AT_CLEANUP
206 ## ------------------- ##
207 ## Missing templates.  ##
208 ## ------------------- ##
210 # Check that config.status detects missing input files
211 AT_SETUP([Missing templates])
213 AT_DATA([configure.ac],
214 [[AC_INIT
215 AC_CONFIG_FILES([nonexistent])
216 AC_OUTPUT
219 AT_CHECK_AUTOCONF
220 AT_CHECK_CONFIGURE([], [1], [],
221 [[config.status: error: cannot find input file: nonexistent.in
223 # Make sure that the output file doesn't exist
224 AT_CHECK([test -f nonexistent], 1)
226 AT_CLEANUP
231 ## ---------------------- ##
232 ## configure invocation.  ##
233 ## ---------------------- ##
235 # Check that `configure' and `config.status' honor their interface.
237 # We run `./configure one=val1 --enable-two=val2 --with-three=val3'
238 # and verify that (i) `configure' correctly receives the arguments and
239 # (ii) correctly passes them to `config.status', which we check by
240 # running `config.status --recheck'.
242 AT_SETUP([configure invocation])
244 AT_DATA([configure.ac],
245 [[AC_INIT
246 echo "result=$one$enable_two$with_three"
247 AC_OUTPUT
250 AT_CHECK_AUTOCONF
252 AT_CHECK_CONFIGURE([one=one --enable-two=two --with-three=three |
253                      sed -n -e 's/^result=//p'], 0,
254                    [onetwothree
256 AT_CHECK([./config.status --recheck | sed -n 's/^result=//p'], 0,
257          [onetwothree
260 AT_CHECK_CONFIGURE([one="\"'$ " --enable-two="\" ' $" --with-three=" \"'$"|
261                       sed -n -e 's/^result=//p'], 0,
262                    ["'$ " ' $ "'$
264 AT_CHECK([./config.status --recheck | sed -n 's/^result=//p'], 0,
265          ["'$ " ' $ "'$
268 AT_CLEANUP
272 ## -------------------------------------------- ##
273 ## Check that `#define' templates are honored.  ##
274 ## -------------------------------------------- ##
276 # Use various forms of `#define' templates, and make sure there are no
277 # problems when a symbol is prefix of another.
279 AT_SETUP([#define header templates])
281 AT_DATA([configure.ac],
282 [[AC_INIT
283 AC_CONFIG_HEADERS(config.h:config.hin)
285 # I18n of dummy variables: their French translations.
286 AC_DEFINE(foo, toto)
287 AC_DEFINE(bar, tata)
288 AC_DEFINE(baz, titi)
289 AC_DEFINE(fubar, tutu)
291 # Symbols which are prefixes of another.
292 AC_DEFINE(a, A)
293 AC_DEFINE(aaa, AAA)
294 AC_DEFINE(aa, AA)
295 AC_CONFIG_FILES(defs)
297 # Things included in confdefs.h, but which make no sense in
298 # config.h, nor in $DEFS.
299 cat <<\EOF >>confdefs.h
300 /* Hi Mum! Look, I am doing C++! */
301 #ifdef __cplusplus
302 void exit (int status);
303 #endif
306 # In addition of config.h output a full DEFS
307 AC_OUTPUT_MAKE_DEFS
308 DEFS_SAVED=$DEFS
309 AC_SUBST(DEFS_SAVED)
310 AC_OUTPUT
313 AT_DATA([defs.in],
314 [[@DEFS_SAVED@
317 AT_DATA([config.hin],
318 [[#define foo   0
319 #  define bar bar
320 #  define baz   "Archimedes was sinking in his baz"
321 #  define fubar                         tutu
322 #define a B
323 #define aa BB
324 #define aaa BBB
325 #undef a
326 #undef aa
327 #undef aaa
330 AT_CHECK_AUTOCONF
331 AT_CHECK_CONFIGURE
333 AT_DATA([expout],
334 [[/* config.h.  Generated by configure.  */
335 #define foo toto
336 #  define bar tata
337 #  define baz titi
338 #  define fubar tutu
339 #define a A
340 #define aa AA
341 #define aaa AAA
342 #define a A
343 #define aa AA
344 #define aaa AAA
346 AT_CHECK([cat config.h], 0, expout)
348 # Check the value of DEFS.
349 AT_DATA([expout],
350 [[-DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -Dfoo=toto -Dbar=tata -Dbaz=titi -Dfubar=tutu -Da=A -Daaa=AAA -Daa=AA
353 # Because we strip trailing spaces in `testsuite' we can't leave one in
354 # expout, hence nuke the one left by AC_OUTPUT_MAKE_DEFS.
355 AT_CHECK([sed -e 's/ $//' defs], 0, expout)
357 AT_CLEANUP
361 ## ------------------------- ##
362 ## Torturing config.status.  ##
363 ## ------------------------- ##
365 ## Require 100 AC_DEFINE and AC_SUBST with a significantly big value.
366 ## This is mostly to check that Autoconf produces portable sed scripts
367 ## in config.status.  sed is used to skip the first two lines
368 ## `Generated by...'.
370 # We use m4_for many times.
371 m4_pattern_allow([^m4_for$])
373 AT_SETUP([Torturing config.status])
375 dnl The value used as a big value for AC_DEFINE.
376 dnl Don't use sh active chars here, below it is also used in a sh
377 dnl assignment.
378 m4_define([AT_BIG_VALUE],
379 [This value should be long enough to torture the various limits of sed and other tools used by Autoconf.])
381 m4_define([AT_DESCRIPTION],
382 [Define to a long string if your `Autoconf' works properly.])
385 # AT_DUMMY_VAR(NUMBER)
386 # --------------------
387 # Build a name used for AC_SUBST and AC_DEFINE.  Put ac_ in it
388 # so that the check for user name space invasion does not complain
389 # of the new variables defined.
391 # Note that you should not use the name ac_dummy, because it will be
392 # turned into ac_uummy during the construction of config.status.  Yes,
393 # this is admittedly a bug, but it would be too hard to fix this.
394 # There is really no point in AC_DEFINE a var named ac_d.*.
395 m4_pattern_allow([^m4_bpatsubst$])
396 m4_define([AT_DUMMY_VAR],
397 [ac_Dummy_[]m4_bpatsubst([000$1], [.*\(...\)$], [\1])])
401 AT_DATA([dummy.in],
402 [m4_for([AT_Count], 1, 100, 1,
403 [@AT_DUMMY_VAR(AT_Count)@
404 ])])
407 # ------------ #
408 # configure.ac #
409 # ------------ #
411 m4_pattern_allow([^m4_(define|defun)$])
412 AT_DATA([configure.ac],
413 dnl The following lines transfer AT_DUMMY_VAR, AT_DESCRIPTION, and
414 dnl AT_BIG_VALUE into the configure.ac as AC_DUMMY_VAR etc.
415 [[m4_define([AC_DUMMY_VAR],]
416 m4_dquote(m4_defn([AT_DUMMY_VAR]))[)]]
418 [[m4_define([AC_DESCRIPTION],]
419 m4_dquote(m4_defn([AT_DESCRIPTION]))[)]]
421 [[m4_define([AC_BIG_VALUE],]
422 m4_dquote(m4_defn([AT_BIG_VALUE]))[)]]
424 [[# AC_DEFUBST(NAME)
425 # ----------------
426 # Related VALUE to NAME both with AC_SUBST and AC_DEFINE.  This is
427 # used in the torture tests.
428 m4_defun([AC_DEFUBST],
429 [AC_DUMMY_VAR($1)="AC_BIG_VALUE"
430 AC_DEFINE_UNQUOTED(AC_DUMMY_VAR($1), "$AC_DUMMY_VAR($1)",
431                    AC_DESCRIPTION)
432 AC_SUBST(AC_DUMMY_VAR($1))])
434 AC_INIT
435 AC_CONFIG_HEADERS(config.h:config.hin)
436 AC_CONFIG_FILES(dummy)
437 m4_for(AC_Count, 1, 100, 1,
438        [AC_DEFUBST(AC_Count)])
439 AC_OUTPUT
440 ]])# configure.ac
442 AT_CHECK_AUTOCONF
443 AT_CHECK_AUTOHEADER
444 AT_CHECK_CONFIGURE
446 # Checking that AC_DEFINE worked properly.
447 AT_DATA([expout],
448 [/* Define to the address where bug reports for this package should be sent. */
449 #define PACKAGE_BUGREPORT ""
451 /* Define to the full name of this package. */
452 #define PACKAGE_NAME ""
454 /* Define to the full name and version of this package. */
455 #define PACKAGE_STRING ""
457 /* Define to the one symbol short name of this package. */
458 #define PACKAGE_TARNAME ""
460 /* Define to the version of this package. */
461 #define PACKAGE_VERSION ""
462 m4_for(AT_Count, 1, 100, 1,
464 /* AT_DESCRIPTION */
465 [#define] AT_DUMMY_VAR(AT_Count) "AT_BIG_VALUE"
466 ])])
467 AT_CHECK([sed -n '4,$ p' config.h], 0, expout)
469 # Checking that AC_SUBST worked properly.
470 AT_DATA([expout],
471 [m4_for(AT_Count, 1, 100, 1,
472 [AT_BIG_VALUE
473 ])])
475 AT_CLEANUP
478 ## -------- ##
479 ## srcdir.  ##
480 ## -------- ##
482 AT_SETUP([srcdir])
484 rm -f -r at-dir
485 mkdir at-dir
486 : >at-dir/bar.in
487 : >foo.in
489 AT_DATA([configure.ac],
490 [[AC_INIT
492 AC_CONFIG_FILES([foo at-dir/bar])
494 AC_CONFIG_COMMANDS([report],
495 [test -f $srcdir/configure.ac ||
496    AC_MSG_ERROR([cannot find $srcdir/configure.ac])],
497                    [srcdir=$srcdir])
499 AC_OUTPUT
500 rm -f -r foo at-dir/bar
503 AT_CHECK_AUTOCONF
505 # In place.
506 AT_CHECK([./configure], [], [ignore])
508 # Relative path.
509 AT_CHECK([cd at-dir && ../configure], [], [ignore])
511 # Absolute path.
512 at_here=`pwd`
513 AT_CHECK([cd at-dir && $at_here/configure], [], [ignore])
515 AT_CLEANUP
518 ## ----------------- ##
519 ## Signal handling.  ##
520 ## ----------------- ##
522 AT_SETUP([Signal handling])
524 AT_DATA([configure.ac],
525 [[AC_INIT
526 kill -2 $$
527 exit 77
530 AT_CHECK_AUTOCONF
531 AT_CHECK_CONFIGURE([], 1, ignore, ignore)
533 AT_CLEANUP
536 ## ---------------------------- ##
537 ## Configuring subdirectories.  ##
538 ## ---------------------------- ##
540 # .
541 # |-- builddir
542 # |   |-- config.log
543 # |   |-- config.status
544 # |   `-- inner
545 # |       |-- config.log
546 # |       |-- config.status
547 # |       `-- innermost
548 # |           `-- config
549 # |-- configure
550 # |-- configure.ac
551 # |-- inner
552 # |   |-- configure
553 # |   |-- configure.ac
554 # |   `-- innermost
555 # |       `-- config.in
556 # `-- install-sh
558 AT_SETUP([Configuring subdirectories])
559 AT_KEYWORDS(autoreconf)
561 # We use aclocal (via autoreconf).
562 AT_CHECK([aclocal --version || exit 77], [], [stdout], [ignore])
563 # It should understand configure.ac.
564 AT_CHECK([[grep '1.[01234]' stdout && exit 77]], [1], [ignore])
566 # The contents of `inner/', and `inner/innermost/'.
567 AS_MKDIR_P([inner/innermost])
569 # We have to use configure.in, not configure.ac, if we still want to
570 # be compatible with Automake 1.4: aclocal (run by autoreconf) would
571 # die because it can't find configure.in.
572 AT_DATA([inner/configure.in],
573 [[AC_INIT(GNU Inner, 1.0)
574 AC_CONFIG_SRCDIR([innermost/config.in])
575 AC_ARG_VAR([INNER], [an inner variable])
576 AC_SUBST([INNER])
577 if test "x$INNER" = x; then
578   INNER=inner
580 AC_CONFIG_FILES([innermost/config])
581 AC_OUTPUT
584 AT_DATA([inner/innermost/config.in],
585 [INNER=@INNER@
586 srcdir=@srcdir@
587 top_srcdir=@top_srcdir@
588 prefix=@prefix@
591 # The contents of `.'
592 AT_DATA([install-sh], [])
594 # nonexistent is allowed not to exist.
595 AT_DATA([configure.in],
596 [[AC_INIT(GNU Outer, 1.0)
597 AC_ARG_VAR([OUTER], [an outer variable])
598 if false; then
599   AC_CONFIG_SUBDIRS([nonexistent])
601 AC_CONFIG_SUBDIRS([inner])
602 AC_OUTPUT
605 # If there are improperly quoted AC_DEFUN installed in share/aclocal,
606 # they trigger warnings from aclocal 1.8, so ignore stderr.
607 AT_CHECK([autoreconf], [], [], [ignore])
608 AT_CHECK([test -f inner/configure])
610 # Running the outer configure recursively should provide the innermost
611 # help strings.
612 AT_CHECK([./configure --help=recursive | grep INNER], 0, [ignore])
614 # Running the outer configure should trigger the inner.
615 AT_CHECK_CONFIGURE
616 AT_CHECK([cat inner/innermost/config], 0,
617 [INNER=inner
618 srcdir=.
619 top_srcdir=..
620 prefix=/usr/local
623 # The same, but from a builddir.
624 AS_MKDIR_P([builddir])
625 AT_CHECK([cd builddir && ../configure], 0, [ignore])
626 AT_CHECK([cat builddir/inner/innermost/config], 0,
627 [INNER=inner
628 srcdir=../../../inner/innermost
629 top_srcdir=../../../inner
630 prefix=/usr/local
633 # Make sure precious variables and command line options are properly
634 # passed, even when there are duplicates.  Run another directory so
635 # that if the user has set config.site to have a config.cache, then
636 # the two runs don't have colliding caches.
637 AS_MKDIR_P([builddir2])
638 AT_CHECK([cd builddir2 && ../configure --prefix /bad --prefix /good INNER=bad INNER=good], 0, [ignore])
639 AT_CHECK([cat builddir2/inner/innermost/config], 0,
640 [INNER=good
641 srcdir=../../../inner/innermost
642 top_srcdir=../../../inner
643 prefix=/good
646 AT_CLEANUP
650 ## -------------- ##
651 ## Deep Package.  ##
652 ## -------------- ##
654 AT_SETUP([Deep Package])
655 AT_KEYWORDS(autoreconf)
657 # We use aclocal (via autoreconf).
658 AT_CHECK([aclocal --version || exit 77], [], [ignore], [ignore])
660 # The contents of `.'
661 AT_DATA([install-sh], [])
662 AT_DATA([configure.in],
663 [[AC_INIT(GNU Outer, 1.0)
664 AC_ARG_VAR([OUTER], [an outer variable])
665 AC_CONFIG_SUBDIRS([inner])
666 AC_OUTPUT
669 # The contents of `inner/', and `inner/innermost/'.
670 AS_MKDIR_P([inner/innermost])
672 AT_DATA([inner/configure.ac],
673 [[AC_INIT(GNU Inner, 1.0)
674 AC_ARG_VAR([INNER], [an inner variable])
675 AC_CONFIG_SUBDIRS(innermost)
676 AC_OUTPUT
679 AT_DATA([inner/innermost/configure.ac],
680 [[AC_INIT(GNU Innermost, 1.0)
681 AC_ARG_VAR([INNERMOST], [an innermost variable])
682 AC_CONFIG_HEADERS(config.h:config.hin)
683 AC_DEFINE_UNQUOTED([INNERMOST], [$INNERMOST], [an innermost variable])
684 AC_OUTPUT
687 AT_CHECK([autoreconf -Wall -v], [0], [ignore], [ignore])
688 AT_CHECK([test -f inner/configure])
689 AT_CHECK([test -f inner/innermost/configure])
690 AT_CHECK([test -f inner/innermost/config.hin])
692 # Running the outer configure recursively should provide the innermost
693 # help strings.
694 AT_CHECK([./configure --help=recursive | grep " INNER "],     0, [ignore])
695 AT_CHECK([./configure --help=recursive | grep " INNERMOST "], 0, [ignore])
697 # Running the outer configure should trigger the inner.
698 AT_CHECK_CONFIGURE([INNERMOST=tsomrenni])
699 AT_CHECK([grep INNERMOST inner/innermost/config.h], 0,
700 [[#define INNERMOST tsomrenni
703 # The same, but from a builddir.
704 AS_MKDIR_P([builddir])
705 AT_CHECK([cd builddir && ../configure INNERMOST=build/tsomrenni], 0, [ignore])
706 AT_CHECK([grep INNERMOST builddir/inner/innermost/config.h], 0,
707 [[#define INNERMOST build/tsomrenni
710 AT_CLEANUP