test-lib: retire $remove_trash variable
The convention "$remove_trash is set to the trash directory that is
used during the test, so that it will be removed at the end, but
under --debug option we set the varilable to empty string to
preserve the directory" made sense back when it was introduced, as
there was no $TRASH_DIRECTORY variable. These days, since no tests
looks at the variable, it is obscure and even risks that by mistake
the variable gets used for something else (e.g. remove_trash=yes)
and cause us misbehave. Worse yet, remove_trash was not initialized
to an empty string at the beginning, so a stray environment variable
the user has could have affected the logic when "--debug" is in use.
Rewrite the clean-up sequence in test_done helper to explicitly
check the $debug condition and remove the trash directory using
the $TRASH_DIRECTORY variable.
Note that "go to the directory one level above the trash and then
remove it" is kept and this is deliverate; test_at_end_hook_ will
keep running from the expected location, and also some platforms may
not like a directory that is serving as the $cwd of a still-active
process removed.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff --git a/t/test-lib.sh b/t/test-lib.sh
index d2f9ad5..51b59c6 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -760,15 +760,14 @@
say "1..$test_count$skip_all"
fi
- if test -n "$remove_trash"
+ if test -z "$debug"
then
- test -d "$remove_trash" ||
+ test -d "$TRASH_DIRECTORY" ||
error "Tests passed but trash directory already removed before test cleanup; aborting"
- cd "$(dirname "$remove_trash")" &&
- rm -rf "$(basename "$remove_trash")" ||
+ cd "$TRASH_DIRECTORY/.." &&
+ rm -fr "$TRASH_DIRECTORY" ||
error "Tests passed but test cleanup failed; aborting"
-
fi
test_at_end_hook_
@@ -924,7 +923,6 @@
/*) ;; # absolute path is good
*) TRASH_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;;
esac
-test ! -z "$debug" || remove_trash=$TRASH_DIRECTORY
rm -fr "$TRASH_DIRECTORY" || {
GIT_EXIT_OK=t
echo >&5 "FATAL: Cannot prepare test area"