summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2015-04-15 16:31:34 -0600
committerEric Blake <eblake@redhat.com>2015-04-21 06:15:35 -0600
commit76754e04fce5f6a7701bec57b057020585df2ae3 (patch)
treedc367be3756d07fa8f3b644bc6f8f7b50f5099e4 /tests
parent7bc2c5623d2fed6421bf95279e5d610ed8dbaa50 (diff)
downloadautoconf-76754e04fce5f6a7701bec57b057020585df2ae3.tar.gz
lib: use shorter way to test if variable is set
Based on an idea by Bernhard Reutner-Fischer. We frequently used the idiom of 'test "${var+set}" = set' to test if $var was set to a non-empty string, but this can portably be trimmed to a more compact 'test ${var+y}' for a smaller configure file. Testing that a variable is not set can be done with '${var+false} :' (although the value of $? is not reliably 1 when the variable is set). The code for AS_VAR_TEST_SET already used the form '${var+:} false', but it is slightly longer, and does not guarantee $? of 1. Tested on coreutils, where the resulting configure file is about 1k smaller. * doc/autoconf.texi (Shell Substitutions): Prefer shorter sequence for testing if a variable is set. (Limitations of Builtins) <test (strings)>: Document it. * configure.ac: Use it. * lib/autoconf/c.m4 (_AC_PROG_CC_G, _AC_PROG_CXX_G) (_AC_PROG_OBJC_G, _AC_PROG_OBJCXX_G): Likewise. * lib/autoconf/fortran.m4 (_AC_PROG_FC_G): Likewise. * lib/autoconf/general.m4 (_AC_ENABLE_IF_ACTION, AC_CACHE_SAVE): Likewise. * lib/autoconf/lang.m4 (_AC_COMPILER_EXEEXT_DEFAULT): Likewise. * lib/autoconf/programs.m4 (AC_PROG_INSTALL, AC_PROG_MKDIR_P) (_AC_PROG_LEX_YYTEXT_DECL): Likewise. * lib/autoconf/status.m4 (_AC_OUTPUT_MAIN_LOOP): Likewise. * lib/autotest/general.m4 (AT_INIT): Likewise. * tests/base.at (AC_CACHE_CHECK): Likewise. * tests/m4sh.at (LINENO): Likewise. * lib/m4sugar/m4sh.m4 (_AS_BOURNE_COMPATIBLE) (_AS_DETECT_BETTER_SHELL, _AS_SHELL_SANITIZE) (_AS_PATH_SEPARATOR_PREPARE): Likewise. (AS_VAR_TEST_SET): Use shorter sequence. Signed-off-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/base.at2
-rw-r--r--tests/m4sh.at4
2 files changed, 3 insertions, 3 deletions
diff --git a/tests/base.at b/tests/base.at
index 63bd36e7..cbc5a598 100644
--- a/tests/base.at
+++ b/tests/base.at
@@ -342,7 +342,7 @@ 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
+if ${my_cv_variable+false} :; then
AC_MSG_ERROR([AC@&@&t@t@_CACHE_VAL did not ensure that the cache variable was set])
fi
diff --git a/tests/m4sh.at b/tests/m4sh.at
index df39ae72..32de374f 100644
--- a/tests/m4sh.at
+++ b/tests/m4sh.at
@@ -214,7 +214,7 @@ AT_KEYWORDS([m4sh])
# unsetting LINENO to compare its result when (i) LINENO is supported
# and when (ii) it is not.
# So just skip if the shell is ZSH.
-AT_CHECK([test -n "${ZSH_VERSION+set}" && exit 77], ignore)
+AT_CHECK([test ${ZSH_VERSION+y} && exit 77], ignore)
# AT_DATA_LINENO(FILE-NAME,
# UNSET-LINENO = true | false, COUNTER, COUNTER-RE)
@@ -297,7 +297,7 @@ test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 2])
AS_LINENO_POP
test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 1])
AS_LINENO_POP
-test x${as_lineno+set} = xset && AS_ERROR([as_lineno set at depth 0])
+test ${as_lineno+y} && AS_ERROR([as_lineno set at depth 0])
AS_EXIT([0])
]])