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>
This commit is contained in:
Johannes Sixt 2009-03-11 22:15:10 +01:00
Родитель 704a3143d5
Коммит 2718e852e9
1 изменённых файлов: 83 добавлений и 33 удалений

Просмотреть файл

@ -7,41 +7,91 @@ test_description='Test various path utilities'
. ./test-lib.sh . ./test-lib.sh
norm_abs() { norm_path() {
test_expect_success "normalize absolute: $1 => $2" \ test_expect_success $3 "normalize path: $1 => $2" \
"test \"\$(test-path-utils normalize_path_copy '$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() { ancestor() {
test_expect_success "longest ancestor: $1 $2 => $3" \ # We do some math with the expected ancestor length.
"test \"\$(test-path-utils longest_ancestor_length '$1' '$2')\" = '$3'" 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 "" "" # Absolute path tests must be skipped on Windows because due to path mangling
norm_abs / / # the test program never sees a POSIX-style absolute path
norm_abs // / case $(uname -s) in
norm_abs /// / *MINGW*)
norm_abs /. / ;;
norm_abs /./ / *)
norm_abs /./.. ++failed++ test_set_prereq POSIX
norm_abs /../. ++failed++ ;;
norm_abs /./../.// ++failed++ esac
norm_abs /dir/.. /
norm_abs /dir/sub/../.. / norm_path "" ""
norm_abs /dir/sub/../../.. ++failed++ norm_path . ""
norm_abs /dir /dir norm_path ./ ""
norm_abs /dir// /dir/ norm_path ./. ""
norm_abs /./dir /dir norm_path ./.. ++failed++
norm_abs /dir/. /dir/ norm_path ../. ++failed++
norm_abs /dir///./ /dir/ norm_path ./../.// ++failed++
norm_abs /dir//sub/.. /dir/ norm_path dir/.. ""
norm_abs /dir/sub/../ /dir/ norm_path dir/sub/../.. ""
norm_abs //dir/sub/../. /dir/ norm_path dir/sub/../../.. ++failed++
norm_abs /dir/s1/../s2/ /dir/s2/ norm_path dir dir
norm_abs /d1/s1///s2/..//../s3/ /d1/s3/ norm_path dir// dir/
norm_abs /d1/s1//../s2/../../d2 /d2 norm_path ./dir dir
norm_abs /d1/.../d2 /d1/.../d2 norm_path dir/. dir/
norm_abs /d1/..././../d2 /d1/d2 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
ancestor / / -1 ancestor / / -1
@ -80,10 +130,10 @@ ancestor /foo/bar /:/foo:/bar/ 4
ancestor /foo/bar /foo:/:/bar/ 4 ancestor /foo/bar /foo:/:/bar/ 4
ancestor /foo/bar /:/bar/:/fo 0 ancestor /foo/bar /:/bar/:/fo 0
ancestor /foo/bar /:/bar/ 0 ancestor /foo/bar /:/bar/ 0
ancestor /foo/bar :://foo/. 4 ancestor /foo/bar .:/foo/. 4
ancestor /foo/bar :://foo/.:: 4 ancestor /foo/bar .:/foo/.:.: 4
ancestor /foo/bar //foo/./::/bar 4 ancestor /foo/bar /foo/./:.:/bar 4
ancestor /foo/bar ::/bar -1 ancestor /foo/bar .:/bar -1
test_expect_success 'strip_path_suffix' ' test_expect_success 'strip_path_suffix' '
test c:/msysgit = $(test-path-utils strip_path_suffix \ test c:/msysgit = $(test-path-utils strip_path_suffix \