threads / patch / 33509

patcht/test-lib.sh: fix TRASH_DIRECTORY handling

Subject: [PATCH] t/test-lib.sh: fix TRASH_DIRECTORY handling

## tl;dr

3 messages between Apr 14, 2013 and Apr 14, 2013. Diffs are folded; open one to read it.

replies: 2people: 3as markdown or json

John Keeping· Apr 14, 2013, 16:34 UTC · lore

After the location of $TRASH_DIRECTORY is adjusted by $TEST_OUTPUT_DIRECTORY, we go on to use the $test variable to make the trash directory and cd into it. This means that when $TEST_OUTPUT_DIRECTORY is not "." and an absolute --root has not been specified, we do not remove the trash directory once the tests are complete (remove_trash is set to $TRASH_DIRECTORY).

Fix this by always referring to the trash directory as $TRASH_DIRECTORY.
Signed-off-by: John Keeping <john@keeping.me.uk>
---
 t/test-lib.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Show changes to t/test-lib.sh +4 −4
diff --git a/t/test-lib.sh b/t/test-lib.sh
index debd8b4..f79745c 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -607,7 +607,7 @@ case "$test" in
  *) TRASH_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$test" ;;
 esac
 test ! -z "$debug" || remove_trash=$TRASH_DIRECTORY
-rm -fr "$test" || {
+rm -fr "$TRASH_DIRECTORY" || {
 	GIT_EXIT_OK=t
 	echo >&5 "FATAL: Cannot prepare test area"
 	exit 1
@@ -618,13 +618,13 @@ export HOME
 
 if test -z "$TEST_NO_CREATE_REPO"
 then
-	test_create_repo "$test"
+	test_create_repo "$TRASH_DIRECTORY"
 else
-	mkdir -p "$test"
+	mkdir -p "$TRASH_DIRECTORY"
 fi
 # Use -P to resolve symlinks in our working directory so that the cwd
 # in subprocesses like git equals our $PWD (for pathname comparisons).
-cd -P "$test" || exit 1
+cd -P "$TRASH_DIRECTORY" || exit 1
 
 this_test=${0##*/}
 this_test=${this_test%%-*}
-- 
1.8.2.694.ga76e9c3.dirty
Jeff King· Apr 14, 2013, 19:38 UTC · re: John Keeping · lore

Re: [PATCH] t/test-lib.sh: fix TRASH_DIRECTORY handling

On Sun, Apr 14, 2013 at 05:34:56PM +0100, John Keeping wrote:
Show 8 quoted lines
> After the location of $TRASH_DIRECTORY is adjusted by
> $TEST_OUTPUT_DIRECTORY, we go on to use the $test variable to make the
> trash directory and cd into it.  This means that when
> $TEST_OUTPUT_DIRECTORY is not "." and an absolute --root has not been
> specified, we do not remove the trash directory once the tests are
> complete (remove_trash is set to $TRASH_DIRECTORY).
> 
> Fix this by always referring to the trash directory as $TRASH_DIRECTORY.

Thanks, this seems to date back all the way to my f423ef5 (tests: allow user to specify trash directory location, 2009-08-09), although I think at that time it was not even possible to run the tests from any other directory. So I am happy to blame Thomas's later patches for violating my assumptions. :)

Definitely:
  Acked-by: Jeff King <peff@peff.net>

It probably makes sense to do the patch below on top, so that the error doesn't happen again (I'd just as soon have it squashed into your patch, since then then the motivation is even more obvious).

-- >8 --
Subject: [PATCH] t/test-lib.sh: drop "$test" variable

The $test variable is used as an interim buffer for constructing $TRASH_DIRECTORY, and is almost compatible with it (the exception being that $test has not been converted to an absolute path). Let's get rid of it entirely so that later code does not accidentally use it, thinking the two are interchangeable.

Signed-off-by: Jeff King <peff@peff.net>
---
 t/test-lib.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Show changes to t/test-lib.sh +5 −5
diff --git a/t/test-lib.sh b/t/test-lib.sh
index a16bc73..b3f2488 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -600,11 +600,11 @@ fi
 fi
 
 # Test repository
-test="trash directory.$(basename "$0" .sh)"
-test -n "$root" && test="$root/$test"
-case "$test" in
-/*) TRASH_DIRECTORY="$test" ;;
- *) TRASH_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$test" ;;
+TRASH_DIRECTORY="trash directory.$(basename "$0" .sh)"
+test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY"
+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" || {
-- 
1.8.2.rc0.33.gd915649
Thomas Rast· Apr 14, 2013, 19:44 UTC · re: Jeff King · lore

Re: [PATCH] t/test-lib.sh: fix TRASH_DIRECTORY handling

Jeff King <peff@peff.net> writes:
Show 20 quoted lines
> On Sun, Apr 14, 2013 at 05:34:56PM +0100, John Keeping wrote:
>
>> After the location of $TRASH_DIRECTORY is adjusted by
>> $TEST_OUTPUT_DIRECTORY, we go on to use the $test variable to make the
>> trash directory and cd into it.  This means that when
>> $TEST_OUTPUT_DIRECTORY is not "." and an absolute --root has not been
>> specified, we do not remove the trash directory once the tests are
>> complete (remove_trash is set to $TRASH_DIRECTORY).
>> 
>> Fix this by always referring to the trash directory as $TRASH_DIRECTORY.
>
> Thanks, this seems to date back all the way to my f423ef5 (tests: allow
> user to specify trash directory location, 2009-08-09), although I think
> at that time it was not even possible to run the tests from any other
> directory. So I am happy to blame Thomas's later patches for violating
> my assumptions. :)
>
> Definitely:
>
>   Acked-by: Jeff King <peff@peff.net>
Indeed, your blame assignment seems correct :-)
Acked-by: Thomas Rast <trast@inf.ethz.ch>
Show 9 quoted lines
> -- >8 --
> Subject: [PATCH] t/test-lib.sh: drop "$test" variable
>
> The $test variable is used as an interim buffer for
> constructing $TRASH_DIRECTORY, and is almost compatible with
> it (the exception being that $test has not been converted to
> an absolute path). Let's get rid of it entirely so that
> later code does not accidentally use it, thinking the two
> are interchangeable.
Agreed.
-- 
Thomas Rast
trast@{inf,student}.ethz.ch

← back to recent threads