From: Paolo Bonzini Date: Sun, 12 Jul 2009 10:22:39 +0000 (+0200) Subject: introduce AT_SKIP_IF and AT_FAIL_IF X-Git-Tag: v2.64~21 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ac0fd199f9027786bc4bb332f9f4116e8b1ffccf;p=thirdparty%2Fautoconf.git introduce AT_SKIP_IF and AT_FAIL_IF * NEWS: Mention AT_SKIP_IF and AT_FAIL_IF. * doc/autoconf.texi (Autotest): Document them. * lib/autotest/general.m4 (_AT_LINE_ESCAPED, AT_SKIP_IF, AT_FAIL_IF, _AT_CHECK_EXIT): New. (AT_CHECK): Use _AT_LINE_ESCAPED. * tests/autotest.st: Add tests for AT_SKIP_IF and AT_FAIL_IF. Use AT_SKIP_IF. * tests/local.st: Use AT_SKIP_IF. --- diff --git a/ChangeLog b/ChangeLog index 67520c05c..565b9e9e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2009-07-13 Paolo Bonzini + + Introduce AT_SKIP_IF and AT_FAIL_IF + * NEWS: Mention AT_SKIP_IF and AT_FAIL_IF. + * doc/autoconf.texi (Autotest): Document them. + * lib/autotest/general.m4 (_AT_LINE_ESCAPED, AT_SKIP_IF, + AT_FAIL_IF, _AT_CHECK_EXIT): New. + (AT_CHECK): Use _AT_LINE_ESCAPED. + * tests/autotest.st: Add tests for AT_SKIP_IF and AT_FAIL_IF. + Use AT_SKIP_IF. + * tests/local.st: Use AT_SKIP_IF. + 2009-07-13 Paolo Bonzini Use m4 -g when available. diff --git a/NEWS b/NEWS index 93a09c9e0..ef67c77cb 100644 --- a/NEWS +++ b/NEWS @@ -23,7 +23,7 @@ GNU Autoconf NEWS - User visible changes. ignore-nolog, stdout-nolog, and stderr-nolog. ** The following documented autotest macros are new: - AT_CHECK_UNQUOTED + AT_CHECK_UNQUOTED AT_FAIL_IF AT_SKIP_IF ** The following documented m4sugar macros are new: m4_argn m4_copy_force m4_default_nblank m4_default_nblank_quoted diff --git a/doc/autoconf.texi b/doc/autoconf.texi index 3528f5325..0802c2a07 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -22653,6 +22653,45 @@ If the current test group fails, log the contents of @var{file}. Several identical calls within one test group have no additional effect. @end defmac +@defmac AT_FAIL_IF (@var{shell-condition}) +@atindex{FAIL_IF} +Make the test group fail, skipping the rest of its execution if +@var{shell-condition} is true. @var{shell-condition} is a shell expression +such as a @code{test} command. Tests before @command{AT_FAIL_IF} +will be executed and may still cause the test group to be skipped. +You can instantiate this macro many times from within the same test group. + +You should use this macro only for very simple failure conditions. If the +@var{shell-condition} could emit any kind of output you should instead +use @command{AT_CHECK} like +@example +AT_CHECK([@var{shell-condition} || exit 99]) +@end example +@noindent +so that such output is properly recorded in the @file{testsuite.log} +file. +@end defmac + +@defmac AT_SKIP_IF (@var{shell-condition}) +@atindex{SKIP_IF} +Determine whether the test should be skipped because it requires +features that are unsupported on the machine under test. +@var{shell-condition} is a shell expression such as a @code{test} +command. Tests before @command{AT_SKIP_IF} will be executed +and may still cause the test group to fail. You can instantiate this +macro many times from within the same test group. + +You should use this macro only for very simple skip conditions. If the +@var{shell-condition} could emit any kind of output you should instead +use @command{AT_CHECK} like +@example +AT_CHECK([@var{shell-condition} || exit 77]) +@end example +@noindent +so that such output is properly recorded in the @file{testsuite.log} +file. +@end defmac + @defmac AT_XFAIL_IF (@var{shell-condition}) @atindex{XFAIL_IF} Determine whether the test is expected to fail because it is a known diff --git a/lib/autotest/general.m4 b/lib/autotest/general.m4 index 603279666..b9beb0e65 100644 --- a/lib/autotest/general.m4 +++ b/lib/autotest/general.m4 @@ -168,6 +168,11 @@ m4_define([AT_LINE], m4_bregexp(/__file__, [/\([^/]*\)$], [[\1]]))])])dnl m4_defn([_AT_LINE_base]):__line__]) +# _AT_LINE_ESCAPED +# ---------------- +# Same as AT_LINE, but already escaped for the shell. +m4_define([_AT_LINE_ESCAPED], ["AS_ESCAPE(m4_dquote(AT_LINE))"]) + # _AT_NORMALIZE_TEST_GROUP_NUMBER(SHELL-VAR) # ------------------------------------------ @@ -1775,6 +1780,36 @@ m4_divert_push([TEST_SCRIPT])dnl ]) +# AT_FAIL_IF(SHELL-EXPRESSION) +# ----------------------------- +# Make the test die with hard failure if SHELL-EXPRESSION evaluates to +# true (exitcode = 0). +_AT_DEFINE_SETUP([AT_FAIL_IF], +[dnl +dnl Try to limit the amount of conditionals that we emit. +m4_case([$1], + [], [], + [false], [], + [:], [_AT_CHECK_EXIT([], [99])], + [true], [_AT_CHECK_EXIT([], [99])], + [_AT_CHECK_EXIT([$1], [99])])]) + + +# AT_SKIP_IF(SHELL-EXPRESSION) +# ----------------------------- +# Skip the rest of the group if SHELL-EXPRESSION evaluates to true +# (exitcode = 0). +_AT_DEFINE_SETUP([AT_SKIP_IF], +[dnl +dnl Try to limit the amount of conditionals that we emit. +m4_case([$1], + [], [], + [false], [], + [:], [_AT_CHECK_EXIT([], [77])], + [true], [_AT_CHECK_EXIT([], [77])], + [_AT_CHECK_EXIT([$1], [77])])]) + + # AT_XFAIL_IF(SHELL-EXPRESSION) # ----------------------------- # Set up the test to be expected to fail if SHELL-EXPRESSION evaluates to @@ -2090,7 +2125,7 @@ m4_define([_AT_CHECK], [m4_define([AT_ingroup])]dnl [{ set +x AS_ECHO(["$at_srcdir/AT_LINE: AS_ESCAPE([[$1]])"]) -_AT_DECIDE_TRACEABLE([$1]) "AS_ESCAPE(m4_dquote(AT_LINE))" +_AT_DECIDE_TRACEABLE([$1]) _AT_LINE_ESCAPED ( $at_check_trace; [$1] ) >>"$at_stdout" 2>>"$at_stderr" at_status=$? at_failed=false @@ -2107,3 +2142,12 @@ m4_ifvaln([$5$6], [AS_IF($at_failed, [$5], [$6])])]dnl [$at_failed && at_fn_log_failure AT_capture_files $at_traceon; } ])# _AT_CHECK + +# _AT_CHECK_EXIT(COMMANDS, [EXIT-STATUS-IF-PASS]) +# ----------------------------------------------- +# Minimal version of _AT_CHECK for AT_SKIP_IF and AT_FAIL_IF. +m4_define([_AT_CHECK_EXIT], +[m4_define([AT_ingroup])]dnl +[AS_ECHO(_AT_LINE_ESCAPED) >"$at_check_line_file" +m4_ifval([$1], [($1) \ + && ])at_fn_check_skip $2 "$at_srcdir/AT_LINE"])# _AT_CHECK_EXIT diff --git a/tests/autotest.at b/tests/autotest.at index 438c01dcf..0063c4a0c 100644 --- a/tests/autotest.at +++ b/tests/autotest.at @@ -169,6 +169,16 @@ AT_SETUP([only test]) AT_CHECK([:]) ]], [missing AT@&t@_CLEANUP detected]) +AT_CHECK_AT_SYNTAX([AT@&t@_FAIL_IF without AT@&t@_SETUP], +[[AT_INIT([incomplete test suite]) +AT_FAIL_IF([:]) +]], [AT@&t@_FAIL_IF: missing AT@&t@_SETUP detected]) + +AT_CHECK_AT_SYNTAX([AT@&t@_SKIP_IF without AT@&t@_SETUP], +[[AT_INIT([incomplete test suite]) +AT_SKIP_IF([:]) +]], [AT@&t@_SKIP_IF: missing AT@&t@_SETUP detected]) + AT_CHECK_AT_SYNTAX([AT@&t@_CHECK without AT@&t@_SETUP], [[AT_INIT([incomplete test suite]) AT_CHECK([:]) @@ -263,6 +273,46 @@ AT_CHECK_AT_TEST([Hard fail], [AT_CHECK([grep '2 failed unexpectedly' micro-suite.log], [], [ignore]) AT_CHECK([grep ok micro-suite.log], [1])]) +AT_CHECK_AT_TEST([AT@&t@_FAIL_IF], + [AT_FAIL_IF([:]) + AT_CLEANUP + AT_SETUP + AT_FAIL_IF([false]) + AT_CLEANUP + AT_SETUP + AT_FAIL_IF([test x = y]) + AT_CLEANUP + AT_SETUP + AT_FAIL_IF([bah]) + AT_CLEANUP + AT_SETUP + AT_FAIL_IF([test x = x]) + AT_CLEANUP + AT_SETUP + AT_FAIL_IF([test $foo = x])], + [], [1], [stdout], [ignore], [], + [AT_CHECK([grep '1 5 failed' stdout], [], [ignore], [ignore])]) + +AT_CHECK_AT_TEST([AT@&t@_SKIP_IF], + [AT_SKIP_IF([:]) + AT_CLEANUP + AT_SETUP + AT_SKIP_IF([false]) + AT_CLEANUP + AT_SETUP + AT_SKIP_IF([test x = y]) + AT_CLEANUP + AT_SETUP + AT_SKIP_IF([bah]) + AT_CLEANUP + AT_SETUP + AT_SKIP_IF([test x = x]) + AT_CLEANUP + AT_SETUP + AT_SKIP_IF([test $foo = x])], + [], [], [], [], [], + [AT_CHECK([grep '2.*skipped' micro-suite.log], [], [ignore], [ignore])]) + AT_CHECK_AT_TEST([Syntax error], [AT_CHECK([:]) AT_CLEANUP @@ -990,8 +1040,8 @@ m4_define([AT_SKIP_PARALLEL_TESTS], [# Per BUGS, we have not yet figured out how to run parallel tests cleanly # under dash and some ksh variants. For now, only run this test under # limited conditions; help is appreciated in widening this test base. -AT_CHECK([${CONFIG_SHELL-$SHELL} -c 'test -n "${BASH_VERSION+set}]]dnl -[[${ZSH_VERSION+set}${TEST_PARALLEL_AUTOTEST+set}"' || exit 77]) +AT_SKIP_IF([${CONFIG_SHELL-$SHELL} -c 'test -z "${BASH_VERSION+set}]]dnl +[[${ZSH_VERSION+set}${TEST_PARALLEL_AUTOTEST+set}"']) # The parallel scheduler requires mkfifo and job control to work. AT_CHECK([mkfifo fifo || exit 77]) AT_CHECK([${CONFIG_SHELL-$SHELL} -c '(set -m && set +m) || exit 77'], diff --git a/tests/local.at b/tests/local.at index 9beea3ac5..8a81835b4 100644 --- a/tests/local.at +++ b/tests/local.at @@ -50,8 +50,8 @@ AT_CHECK([$at_diff "$1" "$2"]) # If the shell handles `-n' well, use it to check the syntax of PROGRAM; # otherwise, do nothing. m4_define([AT_CHECK_SHELL_SYNTAX], -[AS_IF([test "$ac_cv_sh_n_works" = yes], - [AT_CHECK([/bin/sh -n $1])])]) +[AT_SKIP_IF([test "$ac_cv_sh_n_works" != yes]) +AT_CHECK([/bin/sh -n $1])]) m4_define([AT_CHECK_PERL_SYNTAX], [AT_CHECK([autom4te_perllibdir=$abs_top_srcdir/lib $PERL -c "$abs_top_builddir"/bin/$1],