From 8da650b456d8fd744abf401a67535acbdd6c22c7 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Fri, 7 Sep 2012 00:40:57 +0200 Subject: t0060: move tests of real_path() from t0000 to here Suggested by: Johannes Sixt Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t0000-basic.sh | 18 ------------------ t/t0060-path-utils.sh | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 18 deletions(-) (limited to 't') diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index ccb5435b2a..ae6a3f0777 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -450,24 +450,6 @@ test_expect_success 'update-index D/F conflict' ' test $numpath0 = 1 ' -test_expect_success SYMLINKS 'real path works as expected' ' - mkdir first && - ln -s ../.git first/.git && - mkdir second && - ln -s ../first second/other && - mkdir third && - dir="$(cd .git; pwd -P)" && - dir2=third/../second/other/.git && - test "$dir" = "$(test-path-utils real_path $dir2)" && - file="$dir"/index && - test "$file" = "$(test-path-utils real_path $dir2/index)" && - basename=blub && - test "$dir/$basename" = "$(cd .git && test-path-utils real_path "$basename")" && - ln -s ../first/file .git/syml && - sym="$(cd first; pwd -P)"/file && - test "$sym" = "$(test-path-utils real_path "$dir2/syml")" -' - test_expect_success 'very long name in the index handled sanely' ' a=a && # 1 diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index 53cf1f8dc4..c8db144c33 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -139,4 +139,23 @@ test_expect_success 'strip_path_suffix' ' test c:/msysgit = $(test-path-utils strip_path_suffix \ c:/msysgit/libexec//git-core libexec/git-core) ' + +test_expect_success SYMLINKS 'real path works as expected' ' + mkdir first && + ln -s ../.git first/.git && + mkdir second && + ln -s ../first second/other && + mkdir third && + dir="$(cd .git; pwd -P)" && + dir2=third/../second/other/.git && + test "$dir" = "$(test-path-utils real_path $dir2)" && + file="$dir"/index && + test "$file" = "$(test-path-utils real_path $dir2/index)" && + basename=blub && + test "$dir/$basename" = "$(cd .git && test-path-utils real_path "$basename")" && + ln -s ../first/file .git/syml && + sym="$(cd first; pwd -P)"/file && + test "$sym" = "$(test-path-utils real_path "$dir2/syml")" +' + test_done -- cgit v1.2.3 From 17264bcc4f580d5e2a94703967236e770f6e236f Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Fri, 7 Sep 2012 00:40:58 +0200 Subject: t0060: verify that absolute_path() fails if passed the empty string It doesn't, so mark the test as failing. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t0060-path-utils.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 't') diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index c8db144c33..d91e516750 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -140,6 +140,10 @@ test_expect_success 'strip_path_suffix' ' c:/msysgit/libexec//git-core libexec/git-core) ' +test_expect_failure 'absolute path rejects the empty string' ' + test_must_fail test-path-utils absolute_path "" +' + test_expect_success SYMLINKS 'real path works as expected' ' mkdir first && ln -s ../.git first/.git && -- cgit v1.2.3 From a0601dc11fab5b4525a348b2ad6c9bb92529a281 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Fri, 7 Sep 2012 00:40:59 +0200 Subject: absolute_path(): reject the empty string Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t0060-path-utils.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't') diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index d91e516750..924aa607d7 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -140,7 +140,7 @@ test_expect_success 'strip_path_suffix' ' c:/msysgit/libexec//git-core libexec/git-core) ' -test_expect_failure 'absolute path rejects the empty string' ' +test_expect_success 'absolute path rejects the empty string' ' test_must_fail test-path-utils absolute_path "" ' -- cgit v1.2.3 From a5c45218b63ce7ac6f5a4a48c4312a1e37e01f3f Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Fri, 7 Sep 2012 00:41:00 +0200 Subject: t0060: verify that real_path() fails if passed the empty string It doesn't, so mark the test as failing. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t0060-path-utils.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 't') diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index 924aa607d7..1118056a1f 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -144,6 +144,10 @@ test_expect_success 'absolute path rejects the empty string' ' test_must_fail test-path-utils absolute_path "" ' +test_expect_failure 'real path rejects the empty string' ' + test_must_fail test-path-utils real_path "" +' + test_expect_success SYMLINKS 'real path works as expected' ' mkdir first && ln -s ../.git first/.git && -- cgit v1.2.3 From 3efe5d1d32fde899b23ebbb1fde499a0897e1c4e Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Fri, 7 Sep 2012 00:41:01 +0200 Subject: real_path(): reject the empty string Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t0060-path-utils.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't') diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index 1118056a1f..fab5ea28b2 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -144,7 +144,7 @@ test_expect_success 'absolute path rejects the empty string' ' test_must_fail test-path-utils absolute_path "" ' -test_expect_failure 'real path rejects the empty string' ' +test_expect_success 'real path rejects the empty string' ' test_must_fail test-path-utils real_path "" ' -- cgit v1.2.3 From 7bcf48dad83e7a07f27403c2ce9e5c29af9e317d Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Fri, 7 Sep 2012 00:41:02 +0200 Subject: t0060: verify that real_path() works correctly with absolute paths There is currently a bug: if passed an absolute top-level path that doesn't exist (e.g., "/foo") it incorrectly interprets the path as a relative path (e.g., returns "$(pwd)/foo"). So mark the test as failing. These tests are skipped on Windows because test-path-utils operates on a DOS-style absolute path even if a POSIX style absolute path is passed as argument. Adjusted for Windows by: Johannes Sixt Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t0060-path-utils.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 't') diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index fab5ea28b2..3121691c6f 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -148,7 +148,17 @@ test_expect_success 'real path rejects the empty string' ' test_must_fail test-path-utils real_path "" ' -test_expect_success SYMLINKS 'real path works as expected' ' +test_expect_failure POSIX 'real path works on absolute paths' ' + nopath="hopefully-absent-path" && + test "/" = "$(test-path-utils real_path "/")" && + test "/$nopath" = "$(test-path-utils real_path "/$nopath")" && + # Find an existing top-level directory for the remaining tests: + d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") && + test "$d" = "$(test-path-utils real_path "$d")" && + test "$d/$nopath" = "$(test-path-utils real_path "$d/$nopath")" +' + +test_expect_success SYMLINKS 'real path works on symlinks' ' mkdir first && ln -s ../.git first/.git && mkdir second && -- cgit v1.2.3 From f4c21e89d7c6b578140e90c02b40eccb51ab8428 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Fri, 7 Sep 2012 00:41:03 +0200 Subject: real_path(): properly handle nonexistent top-level paths The change has two points: 1. Do not strip off a leading slash, because that erroneously turns an absolute path into a relative path. 2. Do not remove slashes from groups of multiple slashes; instead let chdir() handle them. It could be, for example, that it wants to leave leading double-slashes alone. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t0060-path-utils.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't') diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index 3121691c6f..30361f94a4 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -148,7 +148,7 @@ test_expect_success 'real path rejects the empty string' ' test_must_fail test-path-utils real_path "" ' -test_expect_failure POSIX 'real path works on absolute paths' ' +test_expect_success POSIX 'real path works on absolute paths' ' nopath="hopefully-absent-path" && test "/" = "$(test-path-utils real_path "/")" && test "/$nopath" = "$(test-path-utils real_path "/$nopath")" && -- cgit v1.2.3 From 379a03ad8194192ab7b2910ec3326a981971fda1 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Fri, 7 Sep 2012 00:41:04 +0200 Subject: t0060: verify that real_path() removes extra slashes Adjusted for Windows by: Johannes Sixt Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t0060-path-utils.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 't') diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index 30361f94a4..e40f764d54 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -158,6 +158,24 @@ test_expect_success POSIX 'real path works on absolute paths' ' test "$d/$nopath" = "$(test-path-utils real_path "$d/$nopath")" ' +test_expect_success POSIX 'real path removes extra leading slashes' ' + nopath="hopefully-absent-path" && + test "/" = "$(test-path-utils real_path "///")" && + test "/$nopath" = "$(test-path-utils real_path "///$nopath")" && + # Find an existing top-level directory for the remaining tests: + d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") && + test "$d" = "$(test-path-utils real_path "//$d")" && + test "$d/$nopath" = "$(test-path-utils real_path "//$d/$nopath")" +' + +test_expect_success 'real path removes other extra slashes' ' + nopath="hopefully-absent-path" && + # Find an existing top-level directory for the remaining tests: + d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") && + test "$d" = "$(test-path-utils real_path "$d///")" && + test "$d/$nopath" = "$(test-path-utils real_path "$d///$nopath")" +' + test_expect_success SYMLINKS 'real path works on symlinks' ' mkdir first && ln -s ../.git first/.git && -- cgit v1.2.3 From bacca7852f2f304ebe3f579de1a6cf0152af3df1 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Sun, 9 Sep 2012 17:42:20 +0200 Subject: t0060: split absolute path test in two to exercise some of it on Windows Only the first half of the test works only on POSIX, the second half passes on Windows as well. A later test "real path removes other extra slashes" looks very similar, but it does not make sense to split it in the same way: When two slashes are prepended in front of an absolute DOS-style path on Windows, the meaning of the path is changed (//server/share style), so that the test cannot pass on Windows. Signed-off-by: Johannes Sixt Acked-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t0060-path-utils.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 't') diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index e40f764d54..4ef2345982 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -148,10 +148,14 @@ test_expect_success 'real path rejects the empty string' ' test_must_fail test-path-utils real_path "" ' -test_expect_success POSIX 'real path works on absolute paths' ' +test_expect_success POSIX 'real path works on absolute paths 1' ' nopath="hopefully-absent-path" && test "/" = "$(test-path-utils real_path "/")" && - test "/$nopath" = "$(test-path-utils real_path "/$nopath")" && + test "/$nopath" = "$(test-path-utils real_path "/$nopath")" +' + +test_expect_success 'real path works on absolute paths 2' ' + nopath="hopefully-absent-path" && # Find an existing top-level directory for the remaining tests: d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") && test "$d" = "$(test-path-utils real_path "$d")" && -- cgit v1.2.3