diff mbox series

[v4,01/11] test-lib: bring $remove_trash out of retirement

Message ID patch-01.11-a76ea749bb-20210421T101156Z-avarab@gmail.com (mailing list archive)
State Superseded
Headers show
Series test-lib.sh: new test_commit args, simplification & fixes | expand

Commit Message

Ævar Arnfjörð Bjarmason April 21, 2021, 10:15 a.m. UTC
There's no point in creating a repository or directory only to decide
right afterwards that we're skipping all the tests. We can save
ourselves the redundant "git init" or "mkdir" and "rm -rf" in this

We carry around the "$remove_trash" variable because if the directory
is unexpectedly gone at test_done time we'll hit the error about it
being unexpectedly gone added in df4c0d1a792 (test-lib: abort when
can't remove trash directory, 2017-04-20).

So let's partially revert 06478dab4c (test-lib: retire $remove_trash
variable, 2017-04-23) and move the decision about whether to skip all
tests earlier.

Let's also fix a bug that was with us since abc5d372ec (Enable
parallel tests, 2008-08-08): we would leak $remove_trash from the
environment. We don't want this to error out, so let's reset it to the
empty string first:

     remove_trash=t GIT_SKIP_TESTS=t0001 ./t0001-init.sh

I tested this with --debug, see 4d0912a206 (test-lib.sh: do not barf
under --debug at the end of the test, 2017-04-24) for a bug we don't
want to re-introduce.

While I'm at it let's move the HOME assignment to just before
test_create_repo, it could be lower, but it seems better to set it
before calling anything in test-lib-functions.sh

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
 t/test-lib.sh | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)
diff mbox series


diff --git a/t/test-lib.sh b/t/test-lib.sh
index 3dec266221..105c424bf5 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1169,7 +1169,7 @@  test_done () {
-		if test -z "$debug"
+		if test -z "$debug" && test -n "$remove_trash"
 			test -d "$TRASH_DIRECTORY" ||
 			error "Tests passed but trash directory already removed before test cleanup; aborting"
@@ -1334,6 +1334,22 @@  then
 	exit 1
+# Are we running this test at all?
+if match_pattern_list "$this_test" $GIT_SKIP_TESTS
+	say_color info >&3 "skipping test $this_test altogether"
+	skip_all="skip all tests in $this_test"
+	test_done
+# Last-minute variable setup
 # Test repository
 rm -fr "$TRASH_DIRECTORY" || {
@@ -1341,10 +1357,7 @@  rm -fr "$TRASH_DIRECTORY" || {
 	exit 1
 if test -z "$TEST_NO_CREATE_REPO"
 	test_create_repo "$TRASH_DIRECTORY"
@@ -1356,15 +1369,6 @@  fi
 # in subprocesses like git equals our $PWD (for pathname comparisons).
 cd -P "$TRASH_DIRECTORY" || exit 1
-if match_pattern_list "$this_test" $GIT_SKIP_TESTS
-	say_color info >&3 "skipping test $this_test altogether"
-	skip_all="skip all tests in $this_test"
-	test_done
 if test -n "$write_junit_xml"