1
0
mirror of https://github.com/git/git.git synced 2024-09-27 00:32:13 +02:00
git/t/t0060-path-utils.sh
Johannes Schindelin 4fcc86b07d Introduce the function strip_path_suffix()
The function strip_path_suffix() will try to strip a given suffix from
a given path.  The suffix must start at a directory boundary (i.e. "core"
is not a path suffix of "libexec/git-core", but "git-core" is).

Arbitrary runs of directory separators ("slashes") are assumed identical.

Example:

	strip_path_suffix("C:\\msysgit/\\libexec\\git-core",
		"libexec///git-core", &prefix)

will set prefix to "C:\\msysgit" and return 0.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Acked-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-02-19 22:45:48 -08:00

93 lines
2.2 KiB
Bash
Executable File

#!/bin/sh
#
# Copyright (c) 2008 David Reiss
#
test_description='Test various path utilities'
. ./test-lib.sh
norm_abs() {
test_expect_success "normalize absolute: $1 => $2" \
"test \"\$(test-path-utils normalize_path_copy '$1')\" = '$2'"
}
ancestor() {
test_expect_success "longest ancestor: $1 $2 => $3" \
"test \"\$(test-path-utils longest_ancestor_length '$1' '$2')\" = '$3'"
}
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
ancestor / "" -1
ancestor / / -1
ancestor /foo "" -1
ancestor /foo : -1
ancestor /foo ::. -1
ancestor /foo ::..:: -1
ancestor /foo / 0
ancestor /foo /fo -1
ancestor /foo /foo -1
ancestor /foo /foo/ -1
ancestor /foo /bar -1
ancestor /foo /bar/ -1
ancestor /foo /foo/bar -1
ancestor /foo /foo:/bar/ -1
ancestor /foo /foo/:/bar/ -1
ancestor /foo /foo::/bar/ -1
ancestor /foo /:/foo:/bar/ 0
ancestor /foo /foo:/:/bar/ 0
ancestor /foo /:/bar/:/foo 0
ancestor /foo/bar "" -1
ancestor /foo/bar / 0
ancestor /foo/bar /fo -1
ancestor /foo/bar foo -1
ancestor /foo/bar /foo 4
ancestor /foo/bar /foo/ 4
ancestor /foo/bar /foo/ba -1
ancestor /foo/bar /:/fo 0
ancestor /foo/bar /foo:/foo/ba 4
ancestor /foo/bar /bar -1
ancestor /foo/bar /bar/ -1
ancestor /foo/bar /fo: -1
ancestor /foo/bar :/fo -1
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/ 0
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 \
c:/msysgit/libexec//git-core libexec/git-core)
'
test_done