test: skip clean-up when running under --immediate mode

Some tests try to be too careful about cleaning themselves up and do test_expect_success description ' set-up some test refs and/or configuration && test_when_finished "revert the above changes" && the real test ' Which is nice to make sure that a potential failure would not have unexpected interaction with the next test. This however interferes when "the real test" fails and we want to see what is going on, by running the test with --immediate mode and descending into its trash directory after the test stops. The precondition to run the real test and cause it to fail is all gone after the clean-up procedure defined by test_when_finished is done. Update test_run_ which is the workhorse of running a test script called from test_expect_success and test_expect_failure, so that we do not run clean-up script defined with test_when_finished when a test that is expected to succeed fails under the --immediate mode. Signed-off-by: Junio C Hamano <gitster@pobox.com> Acked-by: Jeff King <peff@peff.net>

Junio C Hamano committed Jun 27, 2011 at 11:02 UTC b586744a864cf4d6886d6436d559302123b01fae
1 file changed +10 -2
t/test-lib.sh
+10 -2
@@ -446,9 +446,14 @@ test_debug () {
446
447 test_run_ () {
448 test_cleanup=:
449 + expecting_failure=$2
450 eval >&3 2>&4 "$1"
451 eval_ret=$?
451 - eval >&3 2>&4 "$test_cleanup"
452 +
453 + if test -z "$immediate" || test $eval_ret = 0 || test -n "$expecting_failure"
454 + then
455 + eval >&3 2>&4 "$test_cleanup"
456 + fi
457 if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"; then
458 echo ""
459 fi
@@ -497,7 +502,7 @@ test_expect_failure () {
502 if ! test_skip "$@"
503 then
504 say >&3 "checking known breakage: $2"
500 - test_run_ "$2"
505 + test_run_ "$2" expecting_failure
506 if [ "$?" = 0 -a "$eval_ret" = 0 ]
507 then
508 test_known_broken_ok_ "$1"
@@ -775,6 +780,9 @@ test_cmp() {
780 #
781 # except that the greeting and config --unset must both succeed for
782 # the test to pass.
783 +#
784 +# Note that under --immediate mode, no clean-up is done to help diagnose
785 +# what went wrong.
786
787 test_when_finished () {
788 test_cleanup="{ $*