Skip to content

Commit 080e295

Browse files
peffgitster
authored andcommitted
t0000: run cleaning test inside sub-test
Our check of test_when_finished is done directly in the main script, and if we failed to clean, we complain and exit immediately. It's nicer to signal a test failure here, for a few reasons: - this gives better output to the user when run under a TAP harness like "prove" - constency; it's the only test left in the file that behaves this way - half of its "if" conditional is nonsense anyway; it picked up a reference to GIT_TEST_FAIL_PREREQS_INTERNAL in dfe1a17 (tests: add a special setup where prerequisites fail, 2019-05-13) along with its neighbors, even though it has nothing to do with that flag We could actually do this without a sub-test at all, and just put our two tests (one to do cleanup, and one to check that it happened) in the main script. But doing it in a subtest is conceptually cleaner (from the perspective of the main test script, we are checking only one thing), and it remains consistent with the "cleanup when failing" test directly after it, which has to happen in a sub-test (to avoid the main script complaining of the failed test). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent efd2600 commit 080e295

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

t/t0000-basic.sh

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -852,16 +852,25 @@ test_expect_success 'lazy prereqs do not turn off tracing' "
852852
grep 'echo trace' lazy-prereq-and-tracing/err
853853
"
854854

855-
clean=no
856855
test_expect_success 'tests clean up after themselves' '
857-
test_when_finished clean=yes
858-
'
856+
run_sub_test_lib_test cleanup "test with cleanup" <<-\EOF &&
857+
clean=no
858+
test_expect_success "do cleanup" "
859+
test_when_finished clean=yes
860+
"
861+
test_expect_success "cleanup happened" "
862+
test $clean = yes
863+
"
864+
test_done
865+
EOF
859866
860-
if test -z "$GIT_TEST_FAIL_PREREQS_INTERNAL" -a $clean != yes
861-
then
862-
say "bug in test framework: basic cleanup command does not work reliably"
863-
exit 1
864-
fi
867+
check_sub_test_lib_test cleanup <<-\EOF
868+
ok 1 - do cleanup
869+
ok 2 - cleanup happened
870+
# passed all 2 test(s)
871+
1..2
872+
EOF
873+
'
865874

866875
test_expect_success 'tests clean up even on failures' "
867876
run_sub_test_lib_test_err \

0 commit comments

Comments
 (0)