autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] introduce AT_SKIP_IF and AT_FAIL_IF


From: Paolo Bonzini
Subject: [PATCH] introduce AT_SKIP_IF and AT_FAIL_IF
Date: Sun, 12 Jul 2009 13:09:54 +0200

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  <address@hidden>

        * 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.

---
 NEWS                    |    3 ++
 doc/autoconf.texi       |   36 ++++++++++++++++++++++++++++
 lib/autotest/general.m4 |   45 +++++++++++++++++++++++++++++++++++-
 tests/autotest.at       |   59 +++++++++++++++++++++++++++++++++++++++++++++-
 tests/local.at          |    4 +-
 5 files changed, 142 insertions(+), 5 deletions(-)

diff --git a/NEWS b/NEWS
index 93a09c9..873fcde 100644
--- a/NEWS
+++ b/NEWS
@@ -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.
 
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 3528f53..a9ebc7e 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -22653,6 +22653,42 @@ Writing Testsuites
 Several identical calls within one test group have no additional effect.
 @end defmac
 
address@hidden AT_FAIL_IF (@var{shell-condition})
address@hidden
+Make the test should fail and skip the rest of its execution if
address@hidden is true.   @var{shell-condition} 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
address@hidden could emit any kind of output you should instead
+use @command{AT_CHECK} like
address@hidden
+AT_CHECK(address@hidden || exit 99)
address@hidden example
address@hidden
+so that such output is properly recorded in @file{testsuite.log}.
address@hidden defmac
+
address@hidden AT_SKIP_IF (@var{shell-condition})
address@hidden
+Determine whether the test should be skipped because it requires
+features that are unsupported on the machine under test.
address@hidden 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
address@hidden could emit any kind of output you should instead
+use @command{AT_CHECK} like
address@hidden
+AT_CHECK(address@hidden || exit 77)
address@hidden example
+so that such output is properly recorded in @file{testsuite.log}.
address@hidden 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 a032462..d01dd55 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)
 # ------------------------------------------
@@ -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
diff --git a/tests/autotest.at b/tests/autotest.at
index 438c01d..d6bf58d 100644
--- a/tests/autotest.at
+++ b/tests/autotest.at
@@ -169,6 +169,21 @@ AT_SETUP([only test])
 AT_CHECK([:])
 ]], [missing AT@&address@hidden detected])
 
+AT_CHECK_AT_SYNTAX([AT@&address@hidden without AT@&address@hidden,
+[[AT_INIT([incomplete test suite])
+AT_FAIL_IF([:])
+]], [AT@&address@hidden: missing AT@&address@hidden detected])
+
+AT_CHECK_AT_SYNTAX([AT@&address@hidden without AT@&address@hidden,
+[[AT_INIT([incomplete test suite])
+AT_SKIP_IF([:])
+]], [AT@&address@hidden: missing AT@&address@hidden detected])
+
+AT_CHECK_AT_SYNTAX([AT@&address@hidden without AT@&address@hidden,
+[[AT_INIT([incomplete test suite])
+AT_CHECK([:])
+]], [AT@&address@hidden: missing AT@&address@hidden detected])
+
 AT_CHECK_AT_SYNTAX([AT@&address@hidden without AT@&address@hidden,
 [[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@&address@hidden,
+  [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@&address@hidden,
+  [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'],
diff --git a/tests/local.at b/tests/local.at
index 9beea3a..8a81835 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],
-- 
1.6.2.5






reply via email to

[Prev in Thread] Current Thread [Next in Thread]