Subject: Re: [PATCH 02/19] tests: add tests for the bash prompt functions in the completion script

From: Johannes Sixt <[email-masked]>
Date: Wed, 09 May 2012 10:07:03 +0200

Am 5/9/2012 2:44, schrieb SZEDER Gábor:
> The tests cover the discovery of the '.git' directory in the
> __gitdir() function in different scenarios, and the prompt itself,
> i.e. branch name, detached heads, operations (rebase, merge,
> cherry-pick, bisect), and status indicators (dirty, stash, untracked
> files; but not the upstream status).

The following patch contains fixups are needed to pass the tests at
this point plus a few more changes.

--- >8 ---
From: Johannes Sixt <[email-masked]>
Subject: [PATCH] fixup! tests: add tests for the bash prompt functions in the
 completion script

- $TRASH_DIRECTORY is /c/dir style path, but git produces c:/dir style
  paths. Use $(pwd), which is short for $(pwd -W) that produces the
  latter, to assemble expected test data and paths read by git.

- As long as GIT_DIR is only exported for use by git and not used by
  the completion functions, the move to $(pwd) is only cosmetic and
  for consistency.

- Insert a #!/bin/sh in the shell script to ensure the test will pass
  should git-rebase ever be ported to C.

Signed-off-by: Johannes Sixt <[email-masked]>
---
 t/t9903-bash-prompt.sh |   29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
index a6c9ce9..3880c56 100755
--- a/t/t9903-bash-prompt.sh
+++ b/t/t9903-bash-prompt.sh
@@ -32,9 +32,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 "$(pwd)/otherrepo/.git" > expected &&
 	(
-		__git_dir="$TRASH_DIRECTORY/otherrepo/.git" &&
+		__git_dir="$(pwd)/otherrepo/.git" &&
 		__gitdir > "$actual"
 	) &&
 	test_cmp expected "$actual"
@@ -59,7 +59,7 @@ test_expect_success 'gitdir - .git directory in cwd' '
 '
 
 test_expect_success 'gitdir - .git directory in parent' '
-	echo "$TRASH_DIRECTORY/.git" > expected &&
+	echo "$(pwd)/.git" > expected &&
 	(
 		cd subdir/subsubdir &&
 		__gitdir > "$actual"
@@ -77,7 +77,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 "$(pwd)/.git" > expected &&
 	(
 		cd .git/refs/heads &&
 		__gitdir > "$actual"
@@ -86,9 +86,9 @@ test_expect_success 'gitdir - parent is a .git directory' '
 '
 
 test_expect_failure 'gitdir - $GIT_DIR set while .git directory in cwd' '
-	echo "$TRASH_DIRECTORY/otherrepo/.git" > expected &&
+	echo "$(pwd)/otherrepo/.git" > expected &&
 	(
-		GIT_DIR="$TRASH_DIRECTORY/otherrepo/.git" &&
+		GIT_DIR="$(pwd)/otherrepo/.git" &&
 		export GIT_DIR &&
 		__gitdir > "$actual"
 	) &&
@@ -96,9 +96,9 @@ test_expect_failure '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 "$(pwd)/otherrepo/.git" > expected &&
 	(
-		GIT_DIR="$TRASH_DIRECTORY/otherrepo/.git" &&
+		GIT_DIR="$(pwd)/otherrepo/.git" &&
 		export GIT_DIR &&
 		cd subdir &&
 		__gitdir > "$actual"
@@ -107,8 +107,8 @@ test_expect_success 'gitdir - $GIT_DIR set while .git directory in parent' '
 '
 
 test_expect_success 'gitdir - gitfile in cwd' '
-	echo "$TRASH_DIRECTORY/otherrepo/.git" > expected &&
-	echo "gitdir: $TRASH_DIRECTORY/otherrepo/.git" > subdir/.git &&
+	echo "$(pwd)/otherrepo/.git" > expected &&
+	echo "gitdir: $(pwd)/otherrepo/.git" > subdir/.git &&
 	test_when_finished "rm -f subdir/.git" &&
 	(
 		cd subdir &&
@@ -118,8 +118,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 "$(pwd)/otherrepo/.git" > expected &&
+	echo "gitdir: $(pwd)/otherrepo/.git" > subdir/.git &&
 	test_when_finished "rm -f subdir/.git" &&
 	(
 		cd subdir/subsubdir &&
@@ -129,7 +129,7 @@ test_expect_success 'gitdir - gitfile in parent' '
 '
 
 test_expect_success SYMLINKS 'gitdir - resulting path avoids symlinks' '
-	echo "$TRASH_DIRECTORY/otherrepo/.git" > expected &&
+	echo "$(pwd)/otherrepo/.git" > expected &&
 	mkdir otherrepo/dir &&
 	test_when_finished "rm -rf otherrepo/dir" &&
 	ln -s otherrepo/dir link &&
@@ -238,11 +238,12 @@ test_expect_success 'prompt - interactive rebase' '
 	printf " (b1|REBASE-i)" > expected
 	echo "#!$SHELL_PATH" >fake_editor.sh &&
 	cat >>fake_editor.sh <<\EOF &&
+#!/bin/sh
 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 "$(pwd)/fake_editor.sh" &&
 	git checkout b1 &&
 	test_when_finished "git checkout master" &&
 	git rebase -i HEAD^ &&
-- 
1.7.10.1.1689.gacdfbde