test: run testcases with POSIX absolute paths on Windows

Some test cases are skipped on Windows by marking with POSIX prereq. This is because arguments look like absolute paths (such as /a/b) for regular Windows programs (*.exe executables, no bash scripts) are changed to Windows paths (like C:/msysgit/a/b). There is no cygpath nor equivalent on msysGit, but it is easy to write one. New subcommand "mingw_path" is added in test-path-utils, so that we can get the expected absolute paths on Windows. E.g. COMMAND LINE Linux output Windows output ================================== ============ =============== test-path-utils mingw_path / / C:/msysgit test-path-utils mingw_path /a/b/ /a/b/ C:/msysgit/a/b/ With this utility, most skipped test cases in t0060 can be turned on to be tested correctly on Windows. Signed-off-by: Jiang Xin <worldhello.net@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jiang Xin committed Jun 25, 2013 at 23:53 UTC abd4284bc62127a2db69c8c81501a56bb29284c8
2 files changed +28 -21
t/t0060-path-utils.sh
+23 -21
@@ -8,13 +8,15 @@ test_description='Test various path utilities'
8 . ./test-lib.sh
9
10 norm_path() {
11 + expected=$(test-path-utils mingw_path "$2")
12 test_expect_success $3 "normalize path: $1 => $2" \
12 - "test \"\$(test-path-utils normalize_path_copy '$1')\" = '$2'"
13 + "test \"\$(test-path-utils normalize_path_copy '$1')\" = '$expected'"
14 }
15
16 relative_path() {
17 + expected=$(test-path-utils mingw_path "$3")
18 test_expect_success $4 "relative path: $1 $2 => $3" \
17 - "test \"\$(test-path-utils relative_path '$1' '$2')\" = '$3'"
19 + "test \"\$(test-path-utils relative_path '$1' '$2')\" = '$expected'"
20 }
21
22 # On Windows, we are using MSYS's bash, which mangles the paths.
@@ -39,8 +41,8 @@ ancestor() {
41 test \"\$actual\" = '$expected'"
42 }
43
42 -# Absolute path tests must be skipped on Windows because due to path mangling
43 -# the test program never sees a POSIX-style absolute path
44 +# Some absolute path tests should be skipped on Windows due to path mangling
45 +# on POSIX-style absolute paths
46 case $(uname -s) in
47 *MINGW*)
48 ;;
@@ -73,30 +75,30 @@ norm_path d1/s1//../s2/../../d2 d2
75 norm_path d1/.../d2 d1/.../d2
76 norm_path d1/..././../d2 d1/d2
77
76 -norm_path / / POSIX
78 +norm_path / /
79 norm_path // / POSIX
80 norm_path /// / POSIX
79 -norm_path /. / POSIX
81 +norm_path /. /
82 norm_path /./ / POSIX
83 norm_path /./.. ++failed++ POSIX
82 -norm_path /../. ++failed++ POSIX
84 +norm_path /../. ++failed++
85 norm_path /./../.// ++failed++ POSIX
86 norm_path /dir/.. / POSIX
87 norm_path /dir/sub/../.. / POSIX
88 norm_path /dir/sub/../../.. ++failed++ POSIX
87 -norm_path /dir /dir POSIX
88 -norm_path /dir// /dir/ POSIX
89 -norm_path /./dir /dir POSIX
90 -norm_path /dir/. /dir/ POSIX
91 -norm_path /dir///./ /dir/ POSIX
92 -norm_path /dir//sub/.. /dir/ POSIX
93 -norm_path /dir/sub/../ /dir/ POSIX
89 +norm_path /dir /dir
90 +norm_path /dir// /dir/
91 +norm_path /./dir /dir
92 +norm_path /dir/. /dir/
93 +norm_path /dir///./ /dir/
94 +norm_path /dir//sub/.. /dir/
95 +norm_path /dir/sub/../ /dir/
96 norm_path //dir/sub/../. /dir/ POSIX
95 -norm_path /dir/s1/../s2/ /dir/s2/ POSIX
96 -norm_path /d1/s1///s2/..//../s3/ /d1/s3/ POSIX
97 -norm_path /d1/s1//../s2/../../d2 /d2 POSIX
98 -norm_path /d1/.../d2 /d1/.../d2 POSIX
99 -norm_path /d1/..././../d2 /d1/d2 POSIX
97 +norm_path /dir/s1/../s2/ /dir/s2/
98 +norm_path /d1/s1///s2/..//../s3/ /d1/s3/
99 +norm_path /d1/s1//../s2/../../d2 /d2
100 +norm_path /d1/.../d2 /d1/.../d2
101 +norm_path /d1/..././../d2 /d1/d2
102
103 ancestor / / -1
104 ancestor /foo / 0
@@ -198,8 +200,8 @@ relative_path / /a/b/ ../../
200 relative_path /a/c /a/b/ ../c
201 relative_path /a/c /a/b ../c
202 relative_path /x/y /a/b/ ../../x/y
201 -relative_path /a/b "<empty>" /a/b POSIX
202 -relative_path /a/b "<null>" /a/b POSIX
203 +relative_path /a/b "<empty>" /a/b
204 +relative_path /a/b "<null>" /a/b
205 relative_path a/b/c/ a/b/ c/
206 relative_path a/b/c/ a/b c/
207 relative_path a/b//c a//b c
test-path-utils.c
+5
@@ -116,6 +116,11 @@ int main(int argc, char **argv)
116 return 0;
117 }
118
119 + if (argc == 3 && !strcmp(argv[1], "mingw_path")) {
120 + puts(argv[2]);
121 + return 0;
122 + }
123 +
124 if (argc == 4 && !strcmp(argv[1], "relative_path")) {
125 struct strbuf sb = STRBUF_INIT;
126 const char *in, *prefix, *rel;