]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Testsuite coverage for AC_CACHE_VAL and caching semantics.
authorRalf Wildenhues <Ralf.Wildenhues@gmx.de>
Tue, 8 Jun 2010 04:49:55 +0000 (06:49 +0200)
committerRalf Wildenhues <Ralf.Wildenhues@gmx.de>
Tue, 8 Jun 2010 04:49:55 +0000 (06:49 +0200)
* tests/base.at (AC_CACHE_CHECK): Extend test.
(AC_CACHE_LOAD): New test.
* tests/torture.at (Configuring subdirectories): Also test
--config-cache with AC_CONFIG_SUBDIRS.
* doc/autoconf.texi (Caching Results): Annotate code snippets
which are tested in the test suite.
(Cache Files): Documented cache variables may be used on the
configure command line to override individual entries in the
cache file.

Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
ChangeLog
doc/autoconf.texi
tests/base.at
tests/torture.at

index f71d53a3469ca4f380358228466f970e975a29c8..ad07b9d6c0ab75348f0d8fd941a4023fc8ca1cfb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2010-06-08  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>
 
+       Testsuite coverage for AC_CACHE_VAL and caching semantics.
+       * tests/base.at (AC_CACHE_CHECK): Extend test.
+       (AC_CACHE_LOAD): New test.
+       * tests/torture.at (Configuring subdirectories): Also test
+       --config-cache with AC_CONFIG_SUBDIRS.
+       * doc/autoconf.texi (Caching Results): Annotate code snippets
+       which are tested in the test suite.
+       (Cache Files): Documented cache variables may be used on the
+       configure command line to override individual entries in the
+       cache file.
+
        Clarify OpenBSD sh errexit issue with compound commands.
        * doc/autoconf.texi (Limitations of Builtins): Only the last
        command in a compound list is problematic.
index 6a7666b55ae22d2ebabe1decddda00e26251b019..0de5485841eba827a5c39b0535810bb34b4186e9 100644 (file)
@@ -9577,6 +9577,7 @@ It is common to find buggy macros using @code{AC_CACHE_VAL} or
 instance, the following macro is broken:
 
 @example
+@c If you change this example, adjust tests/base.at:AC_CACHE_CHECK.
 @group
 AC_DEFUN([AC_SHELL_TRUE],
 [AC_CACHE_CHECK([whether true(1) works], [my_cv_shell_true_works],
@@ -9596,6 +9597,7 @@ This fails if the cache is enabled: the second time this macro is run,
 is:
 
 @example
+@c If you change this example, adjust tests/base.at:AC_CACHE_CHECK.
 @group
 AC_DEFUN([AC_SHELL_TRUE],
 [AC_CACHE_CHECK([whether true(1) works], [my_cv_shell_true_works],
@@ -9675,7 +9677,8 @@ documented semantics.
 A cache file is a shell script that caches the results of configure
 tests run on one system so they can be shared between configure scripts
 and configure runs.  It is not useful on other systems.  If its contents
-are invalid for some reason, the user may delete or edit it.
+are invalid for some reason, the user may delete or edit it, or override
+documented cache variables on the @command{configure} command line.
 
 By default, @command{configure} uses no cache file,
 to avoid problems caused by accidental
index 19b8f88408cb8cf36b11f81f468f06348bc2a33d..c4b627348502a2679756a7a9698353b343cde9fd 100644 (file)
@@ -228,19 +228,39 @@ AT_CLEANUP
 
 AT_SETUP([AC_CACHE_CHECK])
 
+# Don't let a config.site file affect this test.
+AS_UNSET([CONFIG_SITE])
+
 AT_DATA([configure.ac],
 [[AC_INIT
 # m4_define([ac_nothing], [ac_cv_absolutely_nothing])
 AC_CACHE_CHECK([for nothing],
               [ac_nothing],
               [ac_nothing=found])
+
+AC_MSG_CHECKING([for some other variable])
+commands_to_set_it_was_run=false
+AC_CACHE_VAL([my_cv_variable], [
+# FOO
+commands_to_set_it_was_run=true
+my_cv_variable=true
+])
+AC_MSG_RESULT([$my_cv_variable])
+
+# Ensure that the result is available at this point.
+if test ${my_cv_variable+set} != set; then
+  AC_MSG_ERROR([AC@&@&t@t@_CACHE_VAL did not ensure that the cache variable was set])
+fi
+
+# AC_CACHE_SAVE should be enough here, no need for AC_OUTPUT.
+AC_CACHE_SAVE
 ]])
 
 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
+sed 's/^# m4_define/m4_define/' configure.ac > t
 mv -f t configure.ac
 AT_CHECK_AUTOCONF
 AT_CHECK_CONFIGURE([-q])
@@ -250,6 +270,140 @@ mv -f t configure.ac
 AT_CHECK_AUTOCONF
 AT_CHECK_CONFIGURE([-q])
 
+# Print a message saying that the result was cached, iff it was cached.
+AT_CHECK_CONFIGURE([], [], [stdout])
+AT_CHECK([grep 'cached' stdout], [1])
+AT_CHECK_CONFIGURE([my_cv_variable='yes it is set'], [], [stdout])
+AT_CHECK([grep 'cached.*yes it is set' stdout], [], [ignore])
+
+# --cache-file is honored and has caching semantics.
+AT_CHECK_CONFIGURE([--cache-file=foobar.cache], [], [stdout])
+AT_CHECK([grep 'cached' stdout], [1])
+AT_CHECK([test ! -f config.cache])
+AT_CHECK([grep 'my_cv_variable.*true' foobar.cache], [], [ignore])
+AT_CHECK_CONFIGURE([--cache-file=foobar.cache], [], [stdout])
+AT_CHECK([grep 'some other variable.*cached.*true' stdout], [], [ignore])
+
+# A setting on the command line overrides the cache.
+AT_CHECK_CONFIGURE([--cache-file=foobar.cache my_cv_variable='override'], [], [stdout])
+AT_CHECK([grep 'cached.*override' stdout], [], [ignore])
+AT_CHECK([grep 'my_cv_variable.*override' foobar.cache], [], [ignore])
+
+# Values containing braces need special internal treatment.
+AT_CHECK_CONFIGURE([-C ac_cv_nothing='{' my_cv_variable='contains } brace'],
+                  [], [stdout])
+AT_CHECK([grep 'ac_cv_nothing.*{' config.cache], [], [ignore])
+AT_CHECK([grep 'my_cv_variable.*contains } brace' config.cache], [], [ignore])
+AT_CHECK_CONFIGURE([-C], [], [stdout])
+AT_CHECK([grep 'nothing.*{' stdout], [], [ignore])
+AT_CHECK([grep 'some other variable.*contains } brace' stdout], [], [ignore])
+rm -f config.cache
+
+# Diagnose common side-effects that are errors in COMMANDS-TO-SET-IT:
+sed 's/^# FOO/AC_DEFINE([some-define], [1], [oooh.])/' configure.ac > t
+mv -f t configure.ac
+AT_CHECK_AUTOCONF([], [], [], [stderr])
+AT_CHECK([grep 'suspicious.*AC_DEFINE' stderr], [], [ignore])
+
+sed 's/^AC_DEFINE.*/AC_SUBST([some_substitution], [oooh.])/' configure.ac > t
+mv -f t configure.ac
+AT_CHECK_AUTOCONF([], [], [], [stderr])
+AT_CHECK([grep 'suspicious.*AC_SUBST' stderr], [], [ignore])
+
+# Ensure the examples from the manual work as intended.
+# Taken from autoconf.texi:Caching Results
+AT_DATA([configure.ac],
+[[AC_INIT
+AC_DEFUN([AC_SHELL_TRUE],
+[AC_CACHE_CHECK([whether true(1) works], [my_cv_shell_true_works],
+                [my_cv_shell_true_works=no
+                 (true) 2>/dev/null && my_cv_shell_true_works=yes
+                 if test "x$my_cv_shell_true_works" = xyes; then
+                   AC_DEFINE([TRUE_WORKS], [1],
+                             [Define if `true(1)' works properly.])
+                 fi])
+])
+AC_SHELL_TRUE
+]])
+AT_CHECK_AUTOCONF([-Werror], [1], [], [stderr])
+AT_CHECK([grep 'suspicious.*AC_DEFINE' stderr], [], [ignore])
+
+# Taken from autoconf.texi:Caching Results
+AT_DATA([configure.ac],
+[[AC_INIT
+AC_DEFUN([AC_SHELL_TRUE],
+[AC_CACHE_CHECK([whether true(1) works], [my_cv_shell_true_works],
+                [my_cv_shell_true_works=no
+                 (true) 2>/dev/null && my_cv_shell_true_works=yes])
+ if test "x$my_cv_shell_true_works" = xyes; then
+   AC_DEFINE([TRUE_WORKS], [1],
+             [Define if `true(1)' works properly.])
+ fi
+])
+AC_SHELL_TRUE
+AC_OUTPUT
+]])
+AT_CHECK_AUTOCONF([-Werror])
+AT_CHECK_CONFIGURE([-C], [], [stdout])
+AT_CHECK([grep my_cv_shell_true_works config.cache], [], [ignore])
+AT_CHECK([grep 'true.*works.*yes' stdout], [], [ignore])
+
+AT_CHECK_CONFIGURE([--config-cache], [], [stdout])
+AT_CHECK([grep 'true.*works.*cached.*yes' stdout], [], [ignore])
+
+# config.status only pays attention to the cache file with --recheck.
+AT_CHECK([./config.status], [], [stdout])
+AT_CHECK([grep cache stdout], [1])
+AT_CHECK([./config.status --recheck], [], [stdout])
+AT_CHECK([grep cache stdout], [0], [ignore])
+
+# By default, configure uses no cache file, neither loading nor updating it.
+: > a-stamp-file
+AT_CHECK_CONFIGURE([], [], [stdout])
+AT_CHECK([grep cache stdout], [1])
+AT_CHECK([LC_ALL=C ls -t config.cache a-stamp-file | sed 1q | grep config.cache], [1])
+
+# config.site can specify a site-wide cache, accumulating information.
+AT_DATA([config.site],
+[[cache_file=sitecache
+]])
+AT_DATA([sitecache],
+[[my_cv_some_preset_cache_var=yes
+]])
+CONFIG_SITE=config.site
+export CONFIG_SITE
+AT_CHECK_CONFIGURE
+AT_CHECK([grep my_cv_some_preset_cache_var sitecache], [], [ignore])
+AT_CHECK([grep my_cv_shell_true_works sitecache], [], [ignore])
+AT_CHECK_CONFIGURE([], [], [stdout])
+AT_CHECK([grep 'whether true.*works.*cached' stdout], [], [ignore])
+
+AT_CLEANUP
+
+
+## --------------- ##
+## AC_CACHE_LOAD.  ##
+## --------------- ##
+
+# Test AC_CACHE_LOAD.
+
+AT_SETUP([AC_CACHE_LOAD])
+
+AT_DATA([configure.ac],
+[[AC_INIT
+$some_test_code
+AC_CACHE_LOAD
+AC_MSG_NOTICE([some_cv_variable is $some_cv_variable])
+AC_OUTPUT
+]])
+AT_CHECK_AUTOCONF
+AS_UNSET([some_test_code])
+AT_DATA([new-cache],
+[[some_cv_variable=value-from-new-cache
+]])
+AT_CHECK_CONFIGURE([some_test_code='eval cache_file=new-cache'], [], [stdout])
+AT_CHECK([grep 'some_cv_variable.*value-from-new-cache' stdout], [], [ignore])
+
 AT_CLEANUP
 
 
index 1eefd71b8246ac47984680237b49c6d6dc38d085..8ecda2384ea961e8406b0b53282f6314b8731c4a 100644 (file)
@@ -1410,6 +1410,11 @@ AT_CHECK([cd builddir && ../configure $configure_options --silent], 0, [])
 AT_CHECK([cd builddir && ./config.status --recheck], 0, [stdout])
 AT_CHECK([grep 'creating \./config.status' stdout], 0, [ignore])
 
+# --cache-file is adjusted for subdirectories, so the cache is shared.
+AT_CHECK([cd builddir && ../configure $configure_options --config-cache],
+        [], [stdout])
+AT_CHECK([grep 'loading .*\.\./config.cache' stdout], [], [ignore])
+
 # Make sure we can run autoreconf on a subdirectory
 rm -f configure configure.in
 AT_CHECK([autoreconf inner], [], [], [ignore])