From 06478dab4c9fb57dc6b7299eafd18df1bea9ca22 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 23 Apr 2017 17:15:09 -0700 Subject: 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 --- t/test-lib.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/t/test-lib.sh b/t/test-lib.sh index d2f9ad5ae5..51b59c69cb 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -760,15 +760,14 @@ test_done () { 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 @@ case "$TRASH_DIRECTORY" in /*) ;; # 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" -- cgit v1.2.1