Skip to content

Commit b586744

Browse files
committed
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 <[email protected]> Acked-by: Jeff King <[email protected]>
1 parent 534cea3 commit b586744

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

t/test-lib.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,14 @@ test_debug () {
446446

447447
test_run_ () {
448448
test_cleanup=:
449+
expecting_failure=$2
449450
eval >&3 2>&4 "$1"
450451
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
452457
if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"; then
453458
echo ""
454459
fi
@@ -497,7 +502,7 @@ test_expect_failure () {
497502
if ! test_skip "$@"
498503
then
499504
say >&3 "checking known breakage: $2"
500-
test_run_ "$2"
505+
test_run_ "$2" expecting_failure
501506
if [ "$?" = 0 -a "$eval_ret" = 0 ]
502507
then
503508
test_known_broken_ok_ "$1"
@@ -775,6 +780,9 @@ test_cmp() {
775780
#
776781
# except that the greeting and config --unset must both succeed for
777782
# the test to pass.
783+
#
784+
# Note that under --immediate mode, no clean-up is done to help diagnose
785+
# what went wrong.
778786

779787
test_when_finished () {
780788
test_cleanup="{ $*

0 commit comments

Comments
 (0)