threads / discuss / 31794

[minor] two tests broken when run with a --root directory that's a symlink

Subject: [minor] two tests broken when run with a --root directory that's a symlink

## tl;dr

4 messages between Oct 11, 2012 and Oct 11, 2012.

replies: 3people: 4as markdown or json

Ævar Arnfjörð Bjarmason· Oct 11, 2012, 21:55 UTC · lore

These issues are minor, I noticed it because I test with /dev/shm/git as the --root, which on Debian is symlinked to /run/..

    $ rm -rf /tmp/{foo,bar}
    $ mkdir /tmp/target; ln -s /tmp/target /tmp/link
    $ prove ./t4035-diff-quiet.sh ./t9903-bash-prompt.sh :: --root=/tmp/target
    ./t4035-diff-quiet.sh ... ok
    ./t9903-bash-prompt.sh .. ok
    All tests successful.
    Files=2, Tests=64,  1 wallclock secs ( 0.04 usr  0.00 sys +  0.07
cusr  0.06 csys =  0.17 CPU)
    Result: PASS
    $ prove ./t4035-diff-quiet.sh ./t9903-bash-prompt.sh :: --root=/tmp/link
    ./t4035-diff-quiet.sh ... Dubious, test returned 1 (wstat 256, 0x100)
    Failed 3/20 subtests
    ./t9903-bash-prompt.sh .. Dubious, test returned 1 (wstat 256, 0x100)
    Failed 6/44 subtests
Everything else in the test suite passes with a --root that's a symlink.
SZEDER Gábor· Oct 11, 2012, 22:38 UTC · re: Ævar Arnfjörð Bjarmason · lore

[PATCH] bash prompt: fix tests when run with a symlink --root

Some __gitdir() tests fail when they're run with a --root directory which is a symlink, because they use $TRASH_DIRECTORY to construct the expected absolute paths. Use the path got from 'pwd -P' instead throughout the test script.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 t/t9903-bash-prompt.sh | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)
diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
index f17c1f8b..7a7b198f 100755
--- a/t/t9903-bash-prompt.sh
+++ b/t/t9903-bash-prompt.sh
@@ -11,6 +11,8 @@ test_description='test git-specific bash prompt functions'
 
 actual="$TRASH_DIRECTORY/actual"
 
+TRASH_ROOT="$(pwd -P)"
+
 test_expect_success 'setup for prompt tests' '
 	mkdir -p subdir/subsubdir &&
 	git init otherrepo &&
@@ -32,9 +34,9 @@ test_expect_success 'setup for prompt tests' '
 '
 
 test_expect_success 'gitdir - from command line (through $__git_dir)' '
-	echo "$TRASH_DIRECTORY/otherrepo/.git" > expected &&
+	echo "$TRASH_ROOT/otherrepo/.git" > expected &&
 	(
-		__git_dir="$TRASH_DIRECTORY/otherrepo/.git" &&
+		__git_dir="$TRASH_ROOT/otherrepo/.git" &&
 		__gitdir > "$actual"
 	) &&
 	test_cmp expected "$actual"
@@ -59,7 +61,7 @@ test_expect_success 'gitdir - .git directory in cwd' '
 '
 
 test_expect_success 'gitdir - .git directory in parent' '
-	echo "$TRASH_DIRECTORY/.git" > expected &&
+	echo "$TRASH_ROOT/.git" > expected &&
 	(
 		cd subdir/subsubdir &&
 		__gitdir > "$actual"
@@ -77,7 +79,7 @@ test_expect_success 'gitdir - cwd is a .git directory' '
 '
 
 test_expect_success 'gitdir - parent is a .git directory' '
-	echo "$TRASH_DIRECTORY/.git" > expected &&
+	echo "$TRASH_ROOT/.git" > expected &&
 	(
 		cd .git/refs/heads &&
 		__gitdir > "$actual"
@@ -86,9 +88,9 @@ test_expect_success 'gitdir - parent is a .git directory' '
 '
 
 test_expect_success 'gitdir - $GIT_DIR set while .git directory in cwd' '
-	echo "$TRASH_DIRECTORY/otherrepo/.git" > expected &&
+	echo "$TRASH_ROOT/otherrepo/.git" > expected &&
 	(
-		GIT_DIR="$TRASH_DIRECTORY/otherrepo/.git" &&
+		GIT_DIR="$TRASH_ROOT/otherrepo/.git" &&
 		export GIT_DIR &&
 		__gitdir > "$actual"
 	) &&
@@ -96,9 +98,9 @@ test_expect_success 'gitdir - $GIT_DIR set while .git directory in cwd' '
 '
 
 test_expect_success 'gitdir - $GIT_DIR set while .git directory in parent' '
-	echo "$TRASH_DIRECTORY/otherrepo/.git" > expected &&
+	echo "$TRASH_ROOT/otherrepo/.git" > expected &&
 	(
-		GIT_DIR="$TRASH_DIRECTORY/otherrepo/.git" &&
+		GIT_DIR="$TRASH_ROOT/otherrepo/.git" &&
 		export GIT_DIR &&
 		cd subdir &&
 		__gitdir > "$actual"
@@ -108,15 +110,15 @@ test_expect_success 'gitdir - $GIT_DIR set while .git directory in parent' '
 
 test_expect_success 'gitdir - non-existing $GIT_DIR' '
 	(
-		GIT_DIR="$TRASH_DIRECTORY/non-existing" &&
+		GIT_DIR="$TRASH_ROOT/non-existing" &&
 		export GIT_DIR &&
 		test_must_fail __gitdir
 	)
 '
 
 test_expect_success 'gitdir - gitfile in cwd' '
-	echo "$TRASH_DIRECTORY/otherrepo/.git" > expected &&
-	echo "gitdir: $TRASH_DIRECTORY/otherrepo/.git" > subdir/.git &&
+	echo "$TRASH_ROOT/otherrepo/.git" > expected &&
+	echo "gitdir: $TRASH_ROOT/otherrepo/.git" > subdir/.git &&
 	test_when_finished "rm -f subdir/.git" &&
 	(
 		cd subdir &&
@@ -126,8 +128,8 @@ test_expect_success 'gitdir - gitfile in cwd' '
 '
 
 test_expect_success 'gitdir - gitfile in parent' '
-	echo "$TRASH_DIRECTORY/otherrepo/.git" > expected &&
-	echo "gitdir: $TRASH_DIRECTORY/otherrepo/.git" > subdir/.git &&
+	echo "$TRASH_ROOT/otherrepo/.git" > expected &&
+	echo "gitdir: $TRASH_ROOT/otherrepo/.git" > subdir/.git &&
 	test_when_finished "rm -f subdir/.git" &&
 	(
 		cd subdir/subsubdir &&
@@ -137,7 +139,7 @@ test_expect_success 'gitdir - gitfile in parent' '
 '
 
 test_expect_success SYMLINKS 'gitdir - resulting path avoids symlinks' '
-	echo "$TRASH_DIRECTORY/otherrepo/.git" > expected &&
+	echo "$TRASH_ROOT/otherrepo/.git" > expected &&
 	mkdir otherrepo/dir &&
 	test_when_finished "rm -rf otherrepo/dir" &&
 	ln -s otherrepo/dir link &&
@@ -152,7 +154,7 @@ test_expect_success SYMLINKS 'gitdir - resulting path avoids symlinks' '
 test_expect_success 'gitdir - not a git repository' '
 	(
 		cd subdir/subsubdir &&
-		GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY" &&
+		GIT_CEILING_DIRECTORIES="$TRASH_ROOT" &&
 		export GIT_CEILING_DIRECTORIES &&
 		test_must_fail __gitdir
 	)
@@ -250,7 +252,7 @@ echo "edit $(git log -1 --format="%h")" > "$1"
 EOF
 	test_when_finished "rm -f fake_editor.sh" &&
 	chmod a+x fake_editor.sh &&
-	test_set_editor "$TRASH_DIRECTORY/fake_editor.sh" &&
+	test_set_editor "$TRASH_ROOT/fake_editor.sh" &&
 	git checkout b1 &&
 	test_when_finished "git checkout master" &&
 	git rebase -i HEAD^ &&
-- 
1.8.0.rc0.83.gc8e1777
Michael Haggerty· Oct 11, 2012, 22:50 UTC · re: Ævar Arnfjörð Bjarmason · lore

Re: [minor] two tests broken when run with a --root directory that's a symlink

On 10/11/2012 11:55 PM, Ævar Arnfjörð Bjarmason wrote:
Show 19 quoted lines
> These issues are minor, I noticed it because I test with /dev/shm/git
> as the --root, which on Debian is symlinked to /run/..
> 
>     $ rm -rf /tmp/{foo,bar}
>     $ mkdir /tmp/target; ln -s /tmp/target /tmp/link
>     $ prove ./t4035-diff-quiet.sh ./t9903-bash-prompt.sh :: --root=/tmp/target
>     ./t4035-diff-quiet.sh ... ok
>     ./t9903-bash-prompt.sh .. ok
>     All tests successful.
>     Files=2, Tests=64,  1 wallclock secs ( 0.04 usr  0.00 sys +  0.07
> cusr  0.06 csys =  0.17 CPU)
>     Result: PASS
>     $ prove ./t4035-diff-quiet.sh ./t9903-bash-prompt.sh :: --root=/tmp/link
>     ./t4035-diff-quiet.sh ... Dubious, test returned 1 (wstat 256, 0x100)
>     Failed 3/20 subtests
>     ./t9903-bash-prompt.sh .. Dubious, test returned 1 (wstat 256, 0x100)
>     Failed 6/44 subtests
> 
> Everything else in the test suite passes with a --root that's a symlink.

I ran into the same problem a while ago, and submitted a patch series that fixes t4035 (whose problems are related to GIT_CEILING_DIRECTORIES):

    http://thread.gmane.org/gmane.comp.version-control.git/206633

Junio didn't like the approach so much and I haven't yet had time to submit a revised version.

Michael
-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/
Junio C Hamano· Oct 11, 2012, 23:26 UTC · re: Michael Haggerty · lore

Re: [minor] two tests broken when run with a --root directory that's a symlink

Michael Haggerty <mhagger@alum.mit.edu> writes:
Show 7 quoted lines
> I ran into the same problem a while ago, and submitted a patch series
> that fixes t4035 (whose problems are related to GIT_CEILING_DIRECTORIES):
>
>     http://thread.gmane.org/gmane.comp.version-control.git/206633
>
> Junio didn't like the approach so much and I haven't yet had time to
> submit a revised version.

I like the approach of comparing each element of CEILING and the directory not before but after resolving any symlinks in them.

My comments was only about the implementation that seemed to make the API layering boundary more complex than necessary.

← back to recent threads