From 02b35660031e1da4036559fb928589ca8c3844bd Mon Sep 17 00:00:00 2001 From: Bryan Donlan Date: Sun, 4 May 2008 01:37:54 -0400 Subject: test-lib.sh: Add a test_set_editor function to safely set $VISUAL In particular, this function correctly handles cases where the pwd contains spaces, quotes, and other troublesome metacharacters. Signed-off-by: Bryan Donlan Signed-off-by: Junio C Hamano --- t/test-lib.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 't/test-lib.sh') diff --git a/t/test-lib.sh b/t/test-lib.sh index 7c2a8ba77d..d7ad13b955 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -160,6 +160,22 @@ die () { trap 'die' exit +# The semantics of the editor variables are that of invoking +# sh -c "$EDITOR \"$@\"" files ... +# +# If our trash directory contains shell metacharacters, they will be +# interpreted if we just set $EDITOR directly, so do a little dance with +# environment variables to work around this. +# +# In particular, quoting isn't enough, as the path may contain the same quote +# that we're using. +test_set_editor () { + FAKE_EDITOR="$1" + export FAKE_EDITOR + VISUAL='"$FAKE_EDITOR"' + export VISUAL +} + test_tick () { if test -z "${test_tick+set}" then -- cgit v1.2.3 From b480f5cf1a398586d94aecca5d6c9de646837d14 Mon Sep 17 00:00:00 2001 From: Bryan Donlan Date: Sun, 4 May 2008 01:37:56 -0400 Subject: test-lib.sh: Fix some missing path quoting Signed-off-by: Bryan Donlan Signed-off-by: Junio C Hamano --- t/test-lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/test-lib.sh') diff --git a/t/test-lib.sh b/t/test-lib.sh index d7ad13b955..04e098b96e 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -345,7 +345,7 @@ test_create_repo () { repo="$1" mkdir "$repo" cd "$repo" || error "Cannot setup test environment" - "$GIT_EXEC_PATH/git" init --template=$GIT_EXEC_PATH/templates/blt/ >/dev/null 2>&1 || + "$GIT_EXEC_PATH/git" init "--template=$GIT_EXEC_PATH/templates/blt/" >/dev/null 2>&1 || error "cannot run git init -- have you built things yet?" mv .git/hooks .git/hooks-disabled cd "$owd" -- cgit v1.2.3 From 4a7aaccd83a4f9eca17ca936b7c297e01840f587 Mon Sep 17 00:00:00 2001 From: Bryan Donlan Date: Sun, 4 May 2008 01:38:00 -0400 Subject: Rename the test trash directory to contain spaces. In order to help prevent regressions in the future, rename the trash directory for all tests to contain spaces. This patch also corrects two failures that were caused or exposed by this change. Signed-off-by: Bryan Donlan Signed-off-by: Junio C Hamano --- t/.gitignore | 2 +- t/t6200-fmt-merge-msg.sh | 6 +++--- t/test-lib.sh | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 't/test-lib.sh') diff --git a/t/.gitignore b/t/.gitignore index fad67c097b..11ffd910c1 100644 --- a/t/.gitignore +++ b/t/.gitignore @@ -1 +1 @@ -trash +/trash directory diff --git a/t/t6200-fmt-merge-msg.sh b/t/t6200-fmt-merge-msg.sh index 526d7d1c44..9c0b92632c 100755 --- a/t/t6200-fmt-merge-msg.sh +++ b/t/t6200-fmt-merge-msg.sh @@ -82,14 +82,14 @@ test_expect_success 'merge-msg test #1' ' git diff actual expected ' -cat >expected <<\EOF -Merge branch 'left' of ../trash +cat >expected <actual && git diff actual expected diff --git a/t/test-lib.sh b/t/test-lib.sh index 04e098b96e..5002fb04b5 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -411,14 +411,14 @@ fi . ../GIT-BUILD-OPTIONS # Test repository -test=trash +test="trash directory" rm -fr "$test" || { trap - exit echo >&5 "FATAL: Cannot prepare test area" exit 1 } -test_create_repo $test +test_create_repo "$test" cd "$test" this_test=$(expr "./$0" : '.*/\(t[0-9]*\)-[^/]*$') -- cgit v1.2.3