t/helper: merge test-path-utils into test-tool

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Nguyễn Thái Ngọc Duy 2018-03-24 08:44:49 +01:00 коммит произвёл Junio C Hamano
Родитель c033cc1508
Коммит b8d5cf4f96
7 изменённых файлов: 40 добавлений и 37 удалений

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

@ -669,6 +669,7 @@ TEST_BUILTINS_OBJS += test-match-trees.o
TEST_BUILTINS_OBJS += test-mergesort.o
TEST_BUILTINS_OBJS += test-mktemp.o
TEST_BUILTINS_OBJS += test-online-cpus.o
TEST_BUILTINS_OBJS += test-path-utils.o
TEST_BUILTINS_OBJS += test-sha1.o
TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
@ -676,7 +677,6 @@ TEST_PROGRAMS_NEED_X += test-dump-untracked-cache
TEST_PROGRAMS_NEED_X += test-fake-ssh
TEST_PROGRAMS_NEED_X += test-line-buffer
TEST_PROGRAMS_NEED_X += test-parse-options
TEST_PROGRAMS_NEED_X += test-path-utils
TEST_PROGRAMS_NEED_X += test-prio-queue
TEST_PROGRAMS_NEED_X += test-read-cache
TEST_PROGRAMS_NEED_X += test-write-cache

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

@ -1,3 +1,4 @@
#include "test-tool.h"
#include "cache.h"
#include "string-list.h"
@ -170,7 +171,7 @@ static struct test_data dirname_data[] = {
{ NULL, NULL }
};
int cmd_main(int argc, const char **argv)
int cmd__path_utils(int argc, const char **argv)
{
if (argc == 3 && !strcmp(argv[1], "normalize_path_copy")) {
char *buf = xmallocz(strlen(argv[2]));

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

@ -24,6 +24,7 @@ static struct test_cmd cmds[] = {
{ "mergesort", cmd__mergesort },
{ "mktemp", cmd__mktemp },
{ "online-cpus", cmd__online_cpus },
{ "path-utils", cmd__path_utils },
{ "sha1", cmd__sha1 },
};

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

@ -18,6 +18,7 @@ int cmd__match_trees(int argc, const char **argv);
int cmd__mergesort(int argc, const char **argv);
int cmd__mktemp(int argc, const char **argv);
int cmd__online_cpus(int argc, const char **argv);
int cmd__path_utils(int argc, const char **argv);
int cmd__sha1(int argc, const char **argv);
#endif

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

@ -39,7 +39,7 @@ native_path () {
then
path=$(cygpath --windows "$path")
else
path=$(test-path-utils real_path "$path")
path=$(test-tool path-utils real_path "$path")
fi &&
echo "$path"
}

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

@ -8,15 +8,15 @@ test_description='Test various path utilities'
. ./test-lib.sh
norm_path() {
expected=$(test-path-utils print_path "$2")
expected=$(test-tool path-utils print_path "$2")
test_expect_success $3 "normalize path: $1 => $2" \
"test \"\$(test-path-utils normalize_path_copy '$1')\" = '$expected'"
"test \"\$(test-tool path-utils normalize_path_copy '$1')\" = '$expected'"
}
relative_path() {
expected=$(test-path-utils print_path "$3")
expected=$(test-tool path-utils print_path "$3")
test_expect_success $4 "relative path: $1 $2 => $3" \
"test \"\$(test-path-utils relative_path '$1' '$2')\" = '$expected'"
"test \"\$(test-tool path-utils relative_path '$1' '$2')\" = '$expected'"
}
test_submodule_relative_url() {
@ -37,7 +37,7 @@ test_git_path() {
# 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)
rootoff=$(test-tool path-utils normalize_path_copy / | wc -c)
# Account for the trailing LF:
if test $rootoff = 2; then
rootoff= # we are on Unix
@ -46,7 +46,7 @@ else
# In MSYS2, the root directory "/" is translated into a Windows
# directory *with* trailing slash. Let's test for that and adjust
# our expected longest ancestor length accordingly.
case "$(test-path-utils print_path /)" in
case "$(test-tool path-utils print_path /)" in
*/) rootslash=1;;
*) rootslash=0;;
esac
@ -61,7 +61,7 @@ ancestor() {
expected=$(($expected+$rootoff))
fi
test_expect_success "longest ancestor: $1 $2 => $expected" \
"actual=\$(test-path-utils longest_ancestor_length '$1' '$2') &&
"actual=\$(test-tool path-utils longest_ancestor_length '$1' '$2') &&
test \"\$actual\" = '$expected'"
}
@ -77,8 +77,8 @@ case $(uname -s) in
;;
esac
test_expect_success basename 'test-path-utils basename'
test_expect_success dirname 'test-path-utils dirname'
test_expect_success basename 'test-tool path-utils basename'
test_expect_success dirname 'test-tool path-utils dirname'
norm_path "" ""
norm_path . ""
@ -157,48 +157,48 @@ 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 \
test c:/msysgit = $(test-tool path-utils strip_path_suffix \
c:/msysgit/libexec//git-core libexec/git-core)
'
test_expect_success 'absolute path rejects the empty string' '
test_must_fail test-path-utils absolute_path ""
test_must_fail test-tool path-utils absolute_path ""
'
test_expect_success 'real path rejects the empty string' '
test_must_fail test-path-utils real_path ""
test_must_fail test-tool path-utils real_path ""
'
test_expect_success POSIX 'real path works on absolute paths 1' '
nopath="hopefully-absent-path" &&
test "/" = "$(test-path-utils real_path "/")" &&
test "/$nopath" = "$(test-path-utils real_path "/$nopath")"
test "/" = "$(test-tool path-utils real_path "/")" &&
test "/$nopath" = "$(test-tool path-utils real_path "/$nopath")"
'
test_expect_success 'real path works on absolute paths 2' '
nopath="hopefully-absent-path" &&
# Find an existing top-level directory for the remaining tests:
d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") &&
test "$d" = "$(test-path-utils real_path "$d")" &&
test "$d/$nopath" = "$(test-path-utils real_path "$d/$nopath")"
test "$d" = "$(test-tool path-utils real_path "$d")" &&
test "$d/$nopath" = "$(test-tool path-utils real_path "$d/$nopath")"
'
test_expect_success POSIX 'real path removes extra leading slashes' '
nopath="hopefully-absent-path" &&
test "/" = "$(test-path-utils real_path "///")" &&
test "/$nopath" = "$(test-path-utils real_path "///$nopath")" &&
test "/" = "$(test-tool path-utils real_path "///")" &&
test "/$nopath" = "$(test-tool path-utils real_path "///$nopath")" &&
# Find an existing top-level directory for the remaining tests:
d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") &&
test "$d" = "$(test-path-utils real_path "//$d")" &&
test "$d/$nopath" = "$(test-path-utils real_path "//$d/$nopath")"
test "$d" = "$(test-tool path-utils real_path "//$d")" &&
test "$d/$nopath" = "$(test-tool path-utils real_path "//$d/$nopath")"
'
test_expect_success 'real path removes other extra slashes' '
nopath="hopefully-absent-path" &&
# Find an existing top-level directory for the remaining tests:
d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") &&
test "$d" = "$(test-path-utils real_path "$d///")" &&
test "$d/$nopath" = "$(test-path-utils real_path "$d///$nopath")"
test "$d" = "$(test-tool path-utils real_path "$d///")" &&
test "$d/$nopath" = "$(test-tool path-utils real_path "$d///$nopath")"
'
test_expect_success SYMLINKS 'real path works on symlinks' '
@ -209,35 +209,35 @@ test_expect_success SYMLINKS 'real path works on symlinks' '
mkdir third &&
dir="$(cd .git; pwd -P)" &&
dir2=third/../second/other/.git &&
test "$dir" = "$(test-path-utils real_path $dir2)" &&
test "$dir" = "$(test-tool path-utils real_path $dir2)" &&
file="$dir"/index &&
test "$file" = "$(test-path-utils real_path $dir2/index)" &&
test "$file" = "$(test-tool path-utils real_path $dir2/index)" &&
basename=blub &&
test "$dir/$basename" = "$(cd .git && test-path-utils real_path "$basename")" &&
test "$dir/$basename" = "$(cd .git && test-tool path-utils real_path "$basename")" &&
ln -s ../first/file .git/syml &&
sym="$(cd first; pwd -P)"/file &&
test "$sym" = "$(test-path-utils real_path "$dir2/syml")"
test "$sym" = "$(test-tool path-utils real_path "$dir2/syml")"
'
test_expect_success SYMLINKS 'prefix_path works with absolute paths to work tree symlinks' '
ln -s target symlink &&
test "$(test-path-utils prefix_path prefix "$(pwd)/symlink")" = "symlink"
test "$(test-tool path-utils prefix_path prefix "$(pwd)/symlink")" = "symlink"
'
test_expect_success 'prefix_path works with only absolute path to work tree' '
echo "" >expected &&
test-path-utils prefix_path prefix "$(pwd)" >actual &&
test-tool path-utils prefix_path prefix "$(pwd)" >actual &&
test_cmp expected actual
'
test_expect_success 'prefix_path rejects absolute path to dir with same beginning as work tree' '
test_must_fail test-path-utils prefix_path prefix "$(pwd)a"
test_must_fail test-tool path-utils prefix_path prefix "$(pwd)a"
'
test_expect_success SYMLINKS 'prefix_path works with absolute path to a symlink to work tree having same beginning as work tree' '
git init repo &&
ln -s repo repolink &&
test "a" = "$(cd repo && test-path-utils prefix_path prefix "$(pwd)/../repolink/a")"
test "a" = "$(cd repo && test-tool path-utils prefix_path prefix "$(pwd)/../repolink/a")"
'
relative_path /foo/a/b/c/ /foo/a/b/ c/

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

@ -360,7 +360,7 @@ test_expect_success 'GIT_DIR set (1)' '
(
cd work &&
GIT_DIR=../gitfile git rev-parse --git-common-dir >actual &&
test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
test-tool path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
test_cmp expect actual
)
'
@ -371,7 +371,7 @@ test_expect_success 'GIT_DIR set (2)' '
(
cd work &&
GIT_DIR=../gitfile git rev-parse --git-common-dir >actual &&
test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
test-tool path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
test_cmp expect actual
)
'
@ -382,7 +382,7 @@ test_expect_success 'Auto discovery' '
(
cd work &&
git rev-parse --git-common-dir >actual &&
test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
test-tool path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
test_cmp expect actual &&
echo haha >data1 &&
git add data1 &&
@ -400,7 +400,7 @@ test_expect_success '$GIT_DIR/common overrides core.worktree' '
(
cd work &&
git rev-parse --git-common-dir >actual &&
test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
test-tool path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
test_cmp expect actual &&
echo haha >data2 &&
git add data2 &&