git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 11/16] t0060: Fix tests on Windows

From
Johannes Sixt <j6t@kdbg.org>
Date
Mar 21, 2009, 21:26 UTC
Message-ID
<9af33285b3e0a797090b5ff28d982b06ff3a63b0.1237667830.git.j6t@kdbg.org>
In-Reply-To
<cover.1237667830.git.j6t@kdbg.org>

Since the MSYS bash mangles absolute paths that it passes as command line arguments to non-MSYS progams (such as git or test-path-utils), we have to bend over backwards to squeeze some usefulness out of the existing tests.

In particular, a set of path normalization tests is added that test relative paths. Some paths in the ancestor path tests are adjusted to help MSYS bash's path mangling heuristics.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
 t/t0060-path-utils.sh |  116 +++++++++++++++++++++++++++++++++++--------------
 1 files changed, 83 insertions(+), 33 deletions(-)
diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh
index 8336114..86000e2 100755
--- a/t/t0060-path-utils.sh
+++ b/t/t0060-path-utils.sh
@@ -7,41 +7,91 @@ test_description='Test various path utilities'
 
 . ./test-lib.sh
 
-norm_abs() {
-	test_expect_success "normalize absolute: $1 => $2" \
+norm_path() {
+	test_expect_success $3 "normalize path: $1 => $2" \
 	"test \"\$(test-path-utils normalize_path_copy '$1')\" = '$2'"
 }
 
+# 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 "x$expected" != x-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
+# Absolute path tests must be skipped on Windows because due to path mangling
+# the test program never sees a POSIX-style absolute path
+case $(uname -s) in
+*MINGW*)
+	;;
+*)
+	test_set_prereq POSIX
+	;;
+esac
+
+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
+
+norm_path / / POSIX
+norm_path // / POSIX
+norm_path /// / POSIX
+norm_path /. / POSIX
+norm_path /./ / POSIX
+norm_path /./.. ++failed++ POSIX
+norm_path /../. ++failed++ POSIX
+norm_path /./../.// ++failed++ POSIX
+norm_path /dir/.. / POSIX
+norm_path /dir/sub/../.. / POSIX
+norm_path /dir/sub/../../.. ++failed++ POSIX
+norm_path /dir /dir POSIX
+norm_path /dir// /dir/ POSIX
+norm_path /./dir /dir POSIX
+norm_path /dir/. /dir/ POSIX
+norm_path /dir///./ /dir/ POSIX
+norm_path /dir//sub/.. /dir/ POSIX
+norm_path /dir/sub/../ /dir/ POSIX
+norm_path //dir/sub/../. /dir/ POSIX
+norm_path /dir/s1/../s2/ /dir/s2/ POSIX
+norm_path /d1/s1///s2/..//../s3/ /d1/s3/ POSIX
+norm_path /d1/s1//../s2/../../d2 /d2 POSIX
+norm_path /d1/.../d2 /d1/.../d2 POSIX
+norm_path /d1/..././../d2 /d1/d2 POSIX
 
 ancestor / "" -1
 ancestor / / -1
@@ -80,10 +130,10 @@ 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_expect_success 'strip_path_suffix' '
 	test c:/msysgit = $(test-path-utils strip_path_suffix \
-- 
1.6.2.1.224.g2225f
Previous: Johannes SixtNext: Johannes Sixt
Message 14 of 23 in “Tests on Windows - main part”
  1. 00/16 Tests on Windows - main partJohannes Sixt, Mar 21, 2009
  2. 01/16 test-lib: Work around incompatible sort and find on WindowsJohannes Sixt, Mar 21, 2009
  3. 02/16 test-lib: Work around missing sum on WindowsJohannes Sixt, Mar 21, 2009
  4. 03/16 Tests on Windows: $(pwd) must return Windows-style pathsJohannes Sixt, Mar 21, 2009
  5. 04/16 t0050: Check whether git init detected symbolic link support correctlyJohannes Sixt, Mar 21, 2009
  6. 05/16 test-lib: Infrastructure to test and check for prerequisitesJohannes Sixt, Mar 21, 2009
  7. Junio C HamanoMar 21, 2009
  8. 06/16 t3600: Use test prerequisite tagsJohannes Sixt, Mar 21, 2009
  9. Junio C HamanoMar 21, 2009
  10. 07/16 Skip tests that fail if the executable bit is not handled by the filesystemJohannes Sixt, Mar 21, 2009
  11. 08/16 t5302: Use prerequisite tags to skip 64-bit offset testsJohannes Sixt, Mar 21, 2009
  12. 09/16 t9100, t9129: Use prerequisite tags for UTF-8 testsJohannes Sixt, Mar 21, 2009
  13. 10/16 Use prerequisite tags to skip tests that depend on symbolic linksJohannes Sixt, Mar 21, 2009
  14. 11/16 t0060: Fix tests on WindowsJohannes Sixt, Mar 21, 2009
  15. 12/16 Skip tests that require a filesystem that obeys POSIX permissionsJohannes Sixt, Mar 21, 2009
  16. 13/16 t3700: Skip a test with backslashes in pathspecJohannes Sixt, Mar 21, 2009
  17. Junio C HamanoMar 21, 2009
  18. Johannes SixtMar 22, 2009
  19. Junio C HamanoMar 22, 2009
  20. 14/16 Use prerequisites to skip tests that need unzipJohannes Sixt, Mar 21, 2009
  21. 15/16 t7004: Use prerequisite tags to skip tests that need gpgJohannes Sixt, Mar 21, 2009
  22. 16/16 t5503: GIT_DEBUG_SEND_PACK is not supported on MinGWJohannes Sixt, Mar 21, 2009
  23. Johannes SixtMar 21, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.