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>

Junio C Hamano committed Apr 23, 2017 at 17:15 UTC 06478dab4c9fb57dc6b7299eafd18df1bea9ca22
1 file changed +4 -6
t/test-lib.sh
+4 -6
@@ -760,15 +760,14 @@ test_done () {
760 say "1..$test_count$skip_all"
761 fi
762
763 - if test -n "$remove_trash"
763 + if test -z "$debug"
764 then
765 - test -d "$remove_trash" ||
765 + test -d "$TRASH_DIRECTORY" ||
766 error "Tests passed but trash directory already removed before test cleanup; aborting"
767
768 - cd "$(dirname "$remove_trash")" &&
769 - rm -rf "$(basename "$remove_trash")" ||
768 + cd "$TRASH_DIRECTORY/.." &&
769 + rm -fr "$TRASH_DIRECTORY" ||
770 error "Tests passed but test cleanup failed; aborting"
771 -
771 fi
772 test_at_end_hook_
773
@@ -924,7 +923,6 @@ case "$TRASH_DIRECTORY" in
923 /*) ;; # absolute path is good
924 *) TRASH_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;;
925 esac
927 -test ! -z "$debug" || remove_trash=$TRASH_DIRECTORY
926 rm -fr "$TRASH_DIRECTORY" || {
927 GIT_EXIT_OK=t
928 echo >&5 "FATAL: Cannot prepare test area"