introduce AT_SKIP_IF and AT_FAIL_IF

These are lightweight versions of AT_CHECK that automatically
add the equivalent of ! in front of the command and change a
failure exit status to 77 resp. 99.  They expand to just
two lines of shell code at the expense of not supporting
tracing (but then so does AT_XFAIL_IF).

2009-07-12  Paolo Bonzini  <bonzini@gnu.org>

	* 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.
This commit is contained in:
Paolo Bonzini 2009-07-12 12:22:39 +02:00
parent 991f80650d
commit 967cf4d282
5 changed files with 144 additions and 5 deletions

3
NEWS
View File

@ -75,6 +75,9 @@ GNU Autoconf NEWS - User visible changes.
** Autotest testsuites do not attempt to write startup error messages
to the log file before that is opened (regression introduced in 2.63).
** The following Autotest macros are new:
AT_SKIP_IF AT_FAIL_IF
** Configure scripts now use shell functions. This feature leads to
smaller configure files and faster execution.

View File

@ -22653,6 +22653,44 @@ 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
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

View File

@ -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)
# ------------------------------------------
@ -1776,6 +1781,36 @@ m4_divert_push([TEST_SCRIPT])dnl
])
# AT_FAIL_IF(SHELL-EXPRESSION)
# -----------------------------
# Set up the test to be expected to fail 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)
# -----------------------------
# Set up the test to be expected to fail 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
@ -2092,7 +2127,7 @@ m4_define([_AT_CHECK],
[m4_define([AT_ingroup])]dnl
[{ $at_traceoff
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
@ -2109,3 +2144,11 @@ 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_CHECK_EXIT

View File

@ -169,6 +169,21 @@ 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([:])
]], [AT@&t@_CHECK: 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 +278,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 +1045,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'],

View File

@ -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],