After this change, it will still be OK for TAP-based tests not to report any explicit TAP plan -- but they should state *explicitly* that they want to do so, by calling the 'plan_' function with a proper argument (currently, either "later" or "unknonwn").
Motivated by a recent issue introduced by yesterday's commit 'v1.11-1959-g0699a84' (pointed out by Peter Rosin, and fixed by follow-up commit 'v1.11-1961-gea44190'). * tests/tap-functions.sh (plan_): Get rid of '$have_tap_plan_', and refactor use and initialization of '$planned_' in a way that will allow client script to get more information on which kind of plan (if any) has been declared by the former 'plan_' invocation. (skip_all_): Adjust. * tests/defs (exit trap): Only print the "lazy" TAP plan if 'plan_' has requested that *explicitly*. * syntax-check.mk (sc_tests_tap_plan): Remove: it's obsolete now, since a TAP-based test that doesn't call 'plan_' explicitly won't print any TAP plan, and the TAP driver will catch that and report an error. (syntax_check_rules): Adjust. --- syntax-checks.mk | 28 ---------------------------- tests/defs | 2 +- tests/tap-functions.sh | 17 ++++++++++------- 3 files changed, 11 insertions(+), 36 deletions(-) diff --git a/syntax-checks.mk b/syntax-checks.mk index 13531bd..a8bdcad 100644 --- a/syntax-checks.mk +++ b/syntax-checks.mk @@ -68,7 +68,6 @@ sc_tests_automake_fails \ sc_tests_plain_aclocal \ sc_tests_plain_perl \ sc_tests_required_after_defs \ -sc_tests_tap_plan \ sc_tests_overriding_macros_on_cmdline \ sc_tests_plain_sleep \ sc_tests_plain_egrep_fgrep \ @@ -426,33 +425,6 @@ sc_tests_required_after_defs: fi; \ done -## TAP-based test scripts should not forget to declare a TAP plan. In -## case it is not known in advance how many tests will be run, a "lazy" -## plan can be used; but its use should be deliberate, explicitly declared -## with a "plan_ later" call, rather than the result of an oversight. -## This check helps to ensure this is indeed the case. -sc_tests_tap_plan: - @with_plan=`grep -l '^ *plan_ ' $(srcdir)/tests/*.tap`; \ - with_plan=`echo $$with_plan`; \ - ok=:; \ - for t in $(srcdir)/tests/*.tap; do \ - case " $$with_plan " in *" $$t "*) continue;; esac; \ - case $$t in \ - *-w.tap) \ - : it is ok for an *auto-generated* test sourcing an \ - : hand-written one not to declare a TAP plan: that will \ - : be done by the sourced test; \ - t2=`echo $$t | sed -e 's|.*/||' -e 's/-w\.tap$$/.tap/'` \ - && grep -E "^ *\\. *[^ ]*/$$t2\\b" $$t >/dev/null \ - && continue || : ;; \ - esac; \ - ok=false; echo $$t; \ - done; \ - $$ok || { \ - echo 'The tests above do not declare a TAP plan.' 1>&2; \ - exit 1; \ - } - ## Overriding a Makefile macro on the command line is not portable when ## recursive targets are used. Better use an envvar. SHELL is an ## exception, POSIX says it can't come from the environment. V, DESTDIR, diff --git a/tests/defs b/tests/defs index 7af8f25..505a43f 100644 --- a/tests/defs +++ b/tests/defs @@ -1053,7 +1053,7 @@ if test "$sh_errexit_works" = yes; then set +e cd "$testbuilddir" if test $am_using_tap = yes; then - if test $have_tap_plan_ != yes && test $exit_status -eq 0; then + if test "$planned_" = later && test $exit_status -eq 0; then plan_ "now" fi test $exit_status -eq 0 && test $tap_pass_count_ -eq $tap_count_ \ diff --git a/tests/tap-functions.sh b/tests/tap-functions.sh index 50abc70..700904b 100644 --- a/tests/tap-functions.sh +++ b/tests/tap-functions.sh @@ -64,19 +64,22 @@ plan_ () bailout_ "plan_: missing argument" elif test $# -ge 2; then bailout_ "plan_: too many arguments" + elif test x"$planned_" != x"none" && test x"$planned_" != x"later"; then + bailout_ "plan_: called to many times" elif test x"$1" = x"unknown" || test x"$1" = x"later"; then - : No-op. + # This means we want to get back later to declaring the TAP plan. + planned_=later + return 0 elif test x"$1" = x"lazy" || test x"$1" = x"now"; then - echo "1..$tap_count_" # Number of test results seen so far. - have_tap_plan_=yes + planned_=$tap_count_ # Number of test results seen so far. elif test $1 -ge 0; then - echo "1..$1" - have_tap_plan_=yes + planned_=$1 else bailout_ "plan_: invalid argument '$1'" fi + echo "1..$planned_" } -have_tap_plan_=no # Avoid interferences from the environment. +planned_=none # diag_ [EXPLANATION] # ------------------ @@ -176,7 +179,7 @@ skip_row_ () skip_all_ () { echo "1..0 # SKIP" ${1+"$@"} - have_tap_plan_=yes + planned_=0 Exit 0 } -- 1.7.9