Skip to content

Commit abd4284

Browse files
jiangxingitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent db627fd commit abd4284

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

t/t0060-path-utils.sh

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ test_description='Test various path utilities'
88
. ./test-lib.sh
99

1010
norm_path() {
11+
expected=$(test-path-utils mingw_path "$2")
1112
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'"
1314
}
1415

1516
relative_path() {
17+
expected=$(test-path-utils mingw_path "$3")
1618
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'"
1820
}
1921

2022
# On Windows, we are using MSYS's bash, which mangles the paths.
@@ -39,8 +41,8 @@ ancestor() {
3941
test \"\$actual\" = '$expected'"
4042
}
4143

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
4446
case $(uname -s) in
4547
*MINGW*)
4648
;;
@@ -73,30 +75,30 @@ norm_path d1/s1//../s2/../../d2 d2
7375
norm_path d1/.../d2 d1/.../d2
7476
norm_path d1/..././../d2 d1/d2
7577

76-
norm_path / / POSIX
78+
norm_path / /
7779
norm_path // / POSIX
7880
norm_path /// / POSIX
79-
norm_path /. / POSIX
81+
norm_path /. /
8082
norm_path /./ / POSIX
8183
norm_path /./.. ++failed++ POSIX
82-
norm_path /../. ++failed++ POSIX
84+
norm_path /../. ++failed++
8385
norm_path /./../.// ++failed++ POSIX
8486
norm_path /dir/.. / POSIX
8587
norm_path /dir/sub/../.. / POSIX
8688
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/
9496
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
100102

101103
ancestor / / -1
102104
ancestor /foo / 0
@@ -198,8 +200,8 @@ relative_path / /a/b/ ../../
198200
relative_path /a/c /a/b/ ../c
199201
relative_path /a/c /a/b ../c
200202
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
203205
relative_path a/b/c/ a/b/ c/
204206
relative_path a/b/c/ a/b c/
205207
relative_path a/b//c a//b c

test-path-utils.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ int main(int argc, char **argv)
116116
return 0;
117117
}
118118

119+
if (argc == 3 && !strcmp(argv[1], "mingw_path")) {
120+
puts(argv[2]);
121+
return 0;
122+
}
123+
119124
if (argc == 4 && !strcmp(argv[1], "relative_path")) {
120125
struct strbuf sb = STRBUF_INIT;
121126
const char *in, *prefix, *rel;

0 commit comments

Comments
 (0)