Re: [PATCH 4/5] Test and fix normalize_path_copy()

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Johannes Sixt
Date: Sunday, February 8, 2009 - 8:50 am

On Sonntag, 8. Februar 2009, René Scharfe wrote:

To fix t0060 on Windows was not even on the radar of this series.

That said, I'm slowly working on a series that fixes or skips many tests on 
Windows. I currently have the patch below in my tree.

-- Hannes

diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh
index 4ed1f0b..dd2d241 100755
--- a/t/t0060-path-utils.sh
+++ b/t/t0060-path-utils.sh
@@ -7,41 +7,89 @@ test_description='Test various path utilities'
 
 . ./test-lib.sh
 
-norm_abs() {
-	test_expect_success "normalize absolute: $1 => $2" \
+norm_path() {
+	test_expect_success "normalize path: $1 => $2" \
 	"test \"\$(test-path-utils normalize_path_copy '$1')\" = '$2'"
 }
+xnorm_path() { say fix this: "$*"; }
+
+# On Windows, we are using MSYS's bash, which mangles the paths.
+# Absolute paths are anchored at the MSYS installation directory,
+# which means that the path / accounts for this many characters:
+rootoff=$(test-path-utils normalize_path_copy / | wc -c)
+# Account for the trailing LF:
+if test "$rootoff" = 2; then
+	rootoff=	# we are on Unix
+else
+	rootoff=$(($rootoff-1))
+fi
 
 ancestor() {
-	test_expect_success "longest ancestor: $1 $2 => $3" \
-	"test \"\$(test-path-utils longest_ancestor_length '$1' '$2')\" = '$3'"
+	# We do some math with the expected ancestor length.
+	expected=$3
+	if test -n "$rootoff" && ! test "$expected" = -1; then
+		expected=$(($expected+$rootoff))
+	fi
+	test_expect_success "longest ancestor: $1 $2 => $expected" \
+	"actual=\$(test-path-utils longest_ancestor_length '$1' '$2') &&
+	 test \"\$actual\" = '$expected'"
 }
 
-norm_abs "" ""
-norm_abs / /
-norm_abs // /
-norm_abs /// /
-norm_abs /. /
-norm_abs /./ /
-norm_abs /./.. ++failed++
-norm_abs /../. ++failed++
-norm_abs /./../.// ++failed++
-norm_abs /dir/.. /
-norm_abs /dir/sub/../.. /
-norm_abs /dir/sub/../../.. ++failed++
-norm_abs /dir /dir
-norm_abs /dir// /dir/
-norm_abs /./dir /dir
-norm_abs /dir/. /dir/
-norm_abs /dir///./ /dir/
-norm_abs /dir//sub/.. /dir/
-norm_abs /dir/sub/../ /dir/
-norm_abs //dir/sub/../. /dir/
-norm_abs /dir/s1/../s2/ /dir/s2/
-norm_abs /d1/s1///s2/..//../s3/ /d1/s3/
-norm_abs /d1/s1//../s2/../../d2 /d2
-norm_abs /d1/.../d2 /d1/.../d2
-norm_abs /d1/..././../d2 /d1/d2
+do_abs=t
+case $(uname -s) in
+*MINGW*) do_abs=
+esac
+
+norm_path "" ""
+norm_path . ""
+norm_path ./ ""
+norm_path ./. ""
+norm_path .. ++failed++
+norm_path ../sub ++failed++
+norm_path dir/.. ""
+norm_path dir/sub/../.. ""
+norm_path dir/sub/../../.. ++failed++
+norm_path dir dir
+norm_path dir// dir/
+norm_path ./dir dir
+norm_path dir/. dir/
+norm_path dir///./ dir/
+norm_path dir//sub/.. dir/
+norm_path dir/sub/../ dir/
+norm_path dir/sub/../. dir/
+norm_path dir/s1/../s2/ dir/s2/
+norm_path d1/s1///s2/..//../s3/ d1/s3/
+norm_path d1/s1//../s2/../../d2 d2
+norm_path d1/.../d2 d1/.../d2
+norm_path d1/..././../d2 d1/d2
+
+if test -n "$do_abs"; then
+norm_path "" ""
+norm_path / /
+norm_path // /
+norm_path /// /
+norm_path /. /
+norm_path /./ /
+norm_path /./.. ++failed++
+norm_path /../. ++failed++
+norm_path /./../.// ++failed++
+norm_path /dir/.. /
+norm_path /dir/sub/../.. /
+norm_path /dir/sub/../../.. ++failed++
+norm_path /dir /dir
+norm_path /dir// /dir/
+norm_path /./dir /dir
+norm_path /dir/. /dir/
+norm_path /dir///./ /dir/
+norm_path /dir//sub/.. /dir/
+norm_path /dir/sub/../ /dir/
+norm_path //dir/sub/../. /dir/
+norm_path /dir/s1/../s2/ /dir/s2/
+norm_path /d1/s1///s2/..//../s3/ /d1/s3/
+norm_path /d1/s1//../s2/../../d2 /d2
+norm_path /d1/.../d2 /d1/.../d2
+norm_path /d1/..././../d2 /d1/d2
+fi
 
 ancestor / "" -1
 ancestor / / -1
@@ -80,9 +128,9 @@ ancestor /foo/bar /:/foo:/bar/ 4
 ancestor /foo/bar /foo:/:/bar/ 4
 ancestor /foo/bar /:/bar/:/fo 0
 ancestor /foo/bar /:/bar/ 0
-ancestor /foo/bar :://foo/. 4
-ancestor /foo/bar :://foo/.:: 4
-ancestor /foo/bar //foo/./::/bar 4
-ancestor /foo/bar ::/bar -1
+ancestor /foo/bar .:/foo/. 4
+ancestor /foo/bar .:/foo/.:.: 4
+ancestor /foo/bar /foo/./:.:/bar 4
+ancestor /foo/bar .:/bar -1
 
 test_done

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] fix crash in path.c on Windows, René Scharfe, (Wed Feb 4, 4:00 pm)
Re: [PATCH] fix crash in path.c on Windows, Junio C Hamano, (Wed Feb 4, 4:51 pm)
Re: [PATCH] fix crash in path.c on Windows, Johannes Sixt, (Thu Feb 5, 12:57 am)
Re: [PATCH] fix crash in path.c on Windows, René Scharfe, (Thu Feb 5, 9:48 am)
Re: [PATCH] fix crash in path.c on Windows, Johannes Sixt, (Thu Feb 5, 10:13 am)
[PATCH] fix t1504 on Windows, René Scharfe, (Thu Feb 5, 12:35 pm)
Re: [PATCH] fix crash in path.c on Windows, Robin Rosenberg, (Thu Feb 5, 1:41 pm)
Re: [PATCH] fix t1504 on Windows, Johannes Sixt, (Fri Feb 6, 5:55 am)
Re: [PATCH] fix t1504 on Windows, Johannes Schindelin, (Fri Feb 6, 6:11 am)
Re: [PATCH] fix t1504 on Windows, Johannes Sixt, (Fri Feb 6, 6:17 am)
Re: [PATCH] fix t1504 on Windows, Johannes Schindelin, (Fri Feb 6, 6:26 am)
Re: [PATCH] fix t1504 on Windows, Johannes Sixt, (Fri Feb 6, 6:36 am)
Re: [PATCH] fix t1504 on Windows, René Scharfe, (Fri Feb 6, 10:18 am)
Re: [PATCH] fix t1504 on Windows, Johannes Sixt, (Fri Feb 6, 12:23 pm)
Re: [PATCH] fix t1504 on Windows, René Scharfe, (Fri Feb 6, 2:45 pm)
Re: [PATCH] fix t1504 on Windows, René Scharfe, (Fri Feb 6, 5:25 pm)
[PATCH 0/5] Consolidate path normalization functions, Johannes Sixt, (Sat Feb 7, 8:08 am)
[PATCH 3/5] Fix GIT_CEILING_DIRECTORIES on Windows, Johannes Sixt, (Sat Feb 7, 8:08 am)
[PATCH 4/5] Test and fix normalize_path_copy(), Johannes Sixt, (Sat Feb 7, 8:08 am)
[PATCH 5/5] Remove unused normalize_absolute_path(), Johannes Sixt, (Sat Feb 7, 8:08 am)
Re: [PATCH 4/5] Test and fix normalize_path_copy(), Robin Rosenberg, (Sat Feb 7, 5:08 pm)
Re: [PATCH 4/5] Test and fix normalize_path_copy(), Johannes Sixt, (Sun Feb 8, 1:52 am)
Re: [PATCH 4/5] Test and fix normalize_path_copy(), René Scharfe, (Sun Feb 8, 7:46 am)
Re: [PATCH 4/5] Test and fix normalize_path_copy(), Johannes Sixt, (Sun Feb 8, 8:50 am)