@matheusbsbs / matheus-bagliano / commits / 2718e852e9
Fork 0

t0060: Fix tests on Windows

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>

Johannes Sixt committed Mar 11, 2009 at 22:15 UTC 2718e852e9baf98c128aafc508e85b610decad25
1 file changed +83 -33
t/t0060-path-utils.sh
+83 -33
@@ -7,41 +7,91 @@ test_description='Test various path utilities'
7
8 . ./test-lib.sh
9
10 -norm_abs() {
11 - test_expect_success "normalize absolute: $1 => $2" \
10 +norm_path() {
11 + test_expect_success $3 "normalize path: $1 => $2" \
12 "test \"\$(test-path-utils normalize_path_copy '$1')\" = '$2'"
13 }
14
15 +# On Windows, we are using MSYS's bash, which mangles the paths.
16 +# Absolute paths are anchored at the MSYS installation directory,
17 +# which means that the path / accounts for this many characters:
18 +rootoff=$(test-path-utils normalize_path_copy / | wc -c)
19 +# Account for the trailing LF:
20 +if test "$rootoff" = 2; then
21 + rootoff= # we are on Unix
22 +else
23 + rootoff=$(($rootoff-1))
24 +fi
25 +
26 ancestor() {
16 - test_expect_success "longest ancestor: $1 $2 => $3" \
17 - "test \"\$(test-path-utils longest_ancestor_length '$1' '$2')\" = '$3'"
27 + # We do some math with the expected ancestor length.
28 + expected=$3
29 + if test -n "$rootoff" && test "x$expected" != x-1; then
30 + expected=$(($expected+$rootoff))
31 + fi
32 + test_expect_success "longest ancestor: $1 $2 => $expected" \
33 + "actual=\$(test-path-utils longest_ancestor_length '$1' '$2') &&
34 + test \"\$actual\" = '$expected'"
35 }
36
20 -norm_abs "" ""
21 -norm_abs / /
22 -norm_abs // /
23 -norm_abs /// /
24 -norm_abs /. /
25 -norm_abs /./ /
26 -norm_abs /./.. ++failed++
27 -norm_abs /../. ++failed++
28 -norm_abs /./../.// ++failed++
29 -norm_abs /dir/.. /
30 -norm_abs /dir/sub/../.. /
31 -norm_abs /dir/sub/../../.. ++failed++
32 -norm_abs /dir /dir
33 -norm_abs /dir// /dir/
34 -norm_abs /./dir /dir
35 -norm_abs /dir/. /dir/
36 -norm_abs /dir///./ /dir/
37 -norm_abs /dir//sub/.. /dir/
38 -norm_abs /dir/sub/../ /dir/
39 -norm_abs //dir/sub/../. /dir/
40 -norm_abs /dir/s1/../s2/ /dir/s2/
41 -norm_abs /d1/s1///s2/..//../s3/ /d1/s3/
42 -norm_abs /d1/s1//../s2/../../d2 /d2
43 -norm_abs /d1/.../d2 /d1/.../d2
44 -norm_abs /d1/..././../d2 /d1/d2
37 +# Absolute path tests must be skipped on Windows because due to path mangling
38 +# the test program never sees a POSIX-style absolute path
39 +case $(uname -s) in
40 +*MINGW*)
41 + ;;
42 +*)
43 + test_set_prereq POSIX
44 + ;;
45 +esac
46 +
47 +norm_path "" ""
48 +norm_path . ""
49 +norm_path ./ ""
50 +norm_path ./. ""
51 +norm_path ./.. ++failed++
52 +norm_path ../. ++failed++
53 +norm_path ./../.// ++failed++
54 +norm_path dir/.. ""
55 +norm_path dir/sub/../.. ""
56 +norm_path dir/sub/../../.. ++failed++
57 +norm_path dir dir
58 +norm_path dir// dir/
59 +norm_path ./dir dir
60 +norm_path dir/. dir/
61 +norm_path dir///./ dir/
62 +norm_path dir//sub/.. dir/
63 +norm_path dir/sub/../ dir/
64 +norm_path dir/sub/../. dir/
65 +norm_path dir/s1/../s2/ dir/s2/
66 +norm_path d1/s1///s2/..//../s3/ d1/s3/
67 +norm_path d1/s1//../s2/../../d2 d2
68 +norm_path d1/.../d2 d1/.../d2
69 +norm_path d1/..././../d2 d1/d2
70 +
71 +norm_path / / POSIX
72 +norm_path // / POSIX
73 +norm_path /// / POSIX
74 +norm_path /. / POSIX
75 +norm_path /./ / POSIX
76 +norm_path /./.. ++failed++ POSIX
77 +norm_path /../. ++failed++ POSIX
78 +norm_path /./../.// ++failed++ POSIX
79 +norm_path /dir/.. / POSIX
80 +norm_path /dir/sub/../.. / POSIX
81 +norm_path /dir/sub/../../.. ++failed++ POSIX
82 +norm_path /dir /dir POSIX
83 +norm_path /dir// /dir/ POSIX
84 +norm_path /./dir /dir POSIX
85 +norm_path /dir/. /dir/ POSIX
86 +norm_path /dir///./ /dir/ POSIX
87 +norm_path /dir//sub/.. /dir/ POSIX
88 +norm_path /dir/sub/../ /dir/ POSIX
89 +norm_path //dir/sub/../. /dir/ POSIX
90 +norm_path /dir/s1/../s2/ /dir/s2/ POSIX
91 +norm_path /d1/s1///s2/..//../s3/ /d1/s3/ POSIX
92 +norm_path /d1/s1//../s2/../../d2 /d2 POSIX
93 +norm_path /d1/.../d2 /d1/.../d2 POSIX
94 +norm_path /d1/..././../d2 /d1/d2 POSIX
95
96 ancestor / "" -1
97 ancestor / / -1
@@ -80,10 +130,10 @@ ancestor /foo/bar /:/foo:/bar/ 4
130 ancestor /foo/bar /foo:/:/bar/ 4
131 ancestor /foo/bar /:/bar/:/fo 0
132 ancestor /foo/bar /:/bar/ 0
83 -ancestor /foo/bar :://foo/. 4
84 -ancestor /foo/bar :://foo/.:: 4
85 -ancestor /foo/bar //foo/./::/bar 4
86 -ancestor /foo/bar ::/bar -1
133 +ancestor /foo/bar .:/foo/. 4
134 +ancestor /foo/bar .:/foo/.:.: 4
135 +ancestor /foo/bar /foo/./:.:/bar 4
136 +ancestor /foo/bar .:/bar -1
137
138 test_expect_success 'strip_path_suffix' '
139 test c:/msysgit = $(test-path-utils strip_path_suffix \