Skip to content

Commit edc2384

Browse files
avargitster
authored andcommitted
test-lib: bring $remove_trash out of retirement
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 case. We carry around the "$remove_trash" variable because if the directory is unexpectedly gone at test_done time we'll still want to hit the "trash directory already removed" error, but not if we never created the trash directory. See df4c0d1 (test-lib: abort when can't remove trash directory, 2017-04-20) for the addition of that error. So let's partially revert 06478da (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 abc5d37 (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 4d0912a (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 89b43f8 commit edc2384

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

t/test-lib.sh

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ test_done () {
11671167
esac
11681168
fi
11691169

1170-
if test -z "$debug"
1170+
if test -z "$debug" && test -n "$remove_trash"
11711171
then
11721172
test -d "$TRASH_DIRECTORY" ||
11731173
error "Tests passed but trash directory already removed before test cleanup; aborting"
@@ -1332,17 +1332,30 @@ then
13321332
exit 1
13331333
fi
13341334

1335+
# Are we running this test at all?
1336+
remove_trash=
1337+
this_test=${0##*/}
1338+
this_test=${this_test%%-*}
1339+
if match_pattern_list "$this_test" $GIT_SKIP_TESTS
1340+
then
1341+
say_color info >&3 "skipping test $this_test altogether"
1342+
skip_all="skip all tests in $this_test"
1343+
test_done
1344+
fi
1345+
1346+
# Last-minute variable setup
1347+
HOME="$TRASH_DIRECTORY"
1348+
GNUPGHOME="$HOME/gnupg-home-not-used"
1349+
export HOME GNUPGHOME
1350+
13351351
# Test repository
13361352
rm -fr "$TRASH_DIRECTORY" || {
13371353
GIT_EXIT_OK=t
13381354
echo >&5 "FATAL: Cannot prepare test area"
13391355
exit 1
13401356
}
13411357

1342-
HOME="$TRASH_DIRECTORY"
1343-
GNUPGHOME="$HOME/gnupg-home-not-used"
1344-
export HOME GNUPGHOME
1345-
1358+
remove_trash=t
13461359
if test -z "$TEST_NO_CREATE_REPO"
13471360
then
13481361
test_create_repo "$TRASH_DIRECTORY"
@@ -1354,15 +1367,6 @@ fi
13541367
# in subprocesses like git equals our $PWD (for pathname comparisons).
13551368
cd -P "$TRASH_DIRECTORY" || exit 1
13561369

1357-
this_test=${0##*/}
1358-
this_test=${this_test%%-*}
1359-
if match_pattern_list "$this_test" $GIT_SKIP_TESTS
1360-
then
1361-
say_color info >&3 "skipping test $this_test altogether"
1362-
skip_all="skip all tests in $this_test"
1363-
test_done
1364-
fi
1365-
13661370
if test -n "$write_junit_xml"
13671371
then
13681372
junit_xml_dir="$TEST_OUTPUT_DIRECTORY/out"

0 commit comments

Comments
 (0)