Skip to content

Commit b8d5cf4

Browse files
pcloudsgitster
authored andcommitted
t/helper: merge test-path-utils into test-tool
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c033cc1 commit b8d5cf4

File tree

7 files changed

+40
-37
lines changed

7 files changed

+40
-37
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,14 +669,14 @@ TEST_BUILTINS_OBJS += test-match-trees.o
669669
TEST_BUILTINS_OBJS += test-mergesort.o
670670
TEST_BUILTINS_OBJS += test-mktemp.o
671671
TEST_BUILTINS_OBJS += test-online-cpus.o
672+
TEST_BUILTINS_OBJS += test-path-utils.o
672673
TEST_BUILTINS_OBJS += test-sha1.o
673674

674675
TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
675676
TEST_PROGRAMS_NEED_X += test-dump-untracked-cache
676677
TEST_PROGRAMS_NEED_X += test-fake-ssh
677678
TEST_PROGRAMS_NEED_X += test-line-buffer
678679
TEST_PROGRAMS_NEED_X += test-parse-options
679-
TEST_PROGRAMS_NEED_X += test-path-utils
680680
TEST_PROGRAMS_NEED_X += test-prio-queue
681681
TEST_PROGRAMS_NEED_X += test-read-cache
682682
TEST_PROGRAMS_NEED_X += test-write-cache

t/helper/test-path-utils.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "test-tool.h"
12
#include "cache.h"
23
#include "string-list.h"
34

@@ -170,7 +171,7 @@ static struct test_data dirname_data[] = {
170171
{ NULL, NULL }
171172
};
172173

173-
int cmd_main(int argc, const char **argv)
174+
int cmd__path_utils(int argc, const char **argv)
174175
{
175176
if (argc == 3 && !strcmp(argv[1], "normalize_path_copy")) {
176177
char *buf = xmallocz(strlen(argv[2]));

t/helper/test-tool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ static struct test_cmd cmds[] = {
2424
{ "mergesort", cmd__mergesort },
2525
{ "mktemp", cmd__mktemp },
2626
{ "online-cpus", cmd__online_cpus },
27+
{ "path-utils", cmd__path_utils },
2728
{ "sha1", cmd__sha1 },
2829
};
2930

t/helper/test-tool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ int cmd__match_trees(int argc, const char **argv);
1818
int cmd__mergesort(int argc, const char **argv);
1919
int cmd__mktemp(int argc, const char **argv);
2020
int cmd__online_cpus(int argc, const char **argv);
21+
int cmd__path_utils(int argc, const char **argv);
2122
int cmd__sha1(int argc, const char **argv);
2223

2324
#endif

t/lib-git-p4.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ native_path () {
3939
then
4040
path=$(cygpath --windows "$path")
4141
else
42-
path=$(test-path-utils real_path "$path")
42+
path=$(test-tool path-utils real_path "$path")
4343
fi &&
4444
echo "$path"
4545
}

t/t0060-path-utils.sh

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

1010
norm_path() {
11-
expected=$(test-path-utils print_path "$2")
11+
expected=$(test-tool path-utils print_path "$2")
1212
test_expect_success $3 "normalize path: $1 => $2" \
13-
"test \"\$(test-path-utils normalize_path_copy '$1')\" = '$expected'"
13+
"test \"\$(test-tool path-utils normalize_path_copy '$1')\" = '$expected'"
1414
}
1515

1616
relative_path() {
17-
expected=$(test-path-utils print_path "$3")
17+
expected=$(test-tool path-utils print_path "$3")
1818
test_expect_success $4 "relative path: $1 $2 => $3" \
19-
"test \"\$(test-path-utils relative_path '$1' '$2')\" = '$expected'"
19+
"test \"\$(test-tool path-utils relative_path '$1' '$2')\" = '$expected'"
2020
}
2121

2222
test_submodule_relative_url() {
@@ -37,7 +37,7 @@ test_git_path() {
3737
# On Windows, we are using MSYS's bash, which mangles the paths.
3838
# Absolute paths are anchored at the MSYS installation directory,
3939
# which means that the path / accounts for this many characters:
40-
rootoff=$(test-path-utils normalize_path_copy / | wc -c)
40+
rootoff=$(test-tool path-utils normalize_path_copy / | wc -c)
4141
# Account for the trailing LF:
4242
if test $rootoff = 2; then
4343
rootoff= # we are on Unix
@@ -46,7 +46,7 @@ else
4646
# In MSYS2, the root directory "/" is translated into a Windows
4747
# directory *with* trailing slash. Let's test for that and adjust
4848
# our expected longest ancestor length accordingly.
49-
case "$(test-path-utils print_path /)" in
49+
case "$(test-tool path-utils print_path /)" in
5050
*/) rootslash=1;;
5151
*) rootslash=0;;
5252
esac
@@ -61,7 +61,7 @@ ancestor() {
6161
expected=$(($expected+$rootoff))
6262
fi
6363
test_expect_success "longest ancestor: $1 $2 => $expected" \
64-
"actual=\$(test-path-utils longest_ancestor_length '$1' '$2') &&
64+
"actual=\$(test-tool path-utils longest_ancestor_length '$1' '$2') &&
6565
test \"\$actual\" = '$expected'"
6666
}
6767

@@ -77,8 +77,8 @@ case $(uname -s) in
7777
;;
7878
esac
7979

80-
test_expect_success basename 'test-path-utils basename'
81-
test_expect_success dirname 'test-path-utils dirname'
80+
test_expect_success basename 'test-tool path-utils basename'
81+
test_expect_success dirname 'test-tool path-utils dirname'
8282

8383
norm_path "" ""
8484
norm_path . ""
@@ -157,48 +157,48 @@ ancestor /foo/bar /foo:/bar 4
157157
ancestor /foo/bar /bar -1
158158

159159
test_expect_success 'strip_path_suffix' '
160-
test c:/msysgit = $(test-path-utils strip_path_suffix \
160+
test c:/msysgit = $(test-tool path-utils strip_path_suffix \
161161
c:/msysgit/libexec//git-core libexec/git-core)
162162
'
163163

164164
test_expect_success 'absolute path rejects the empty string' '
165-
test_must_fail test-path-utils absolute_path ""
165+
test_must_fail test-tool path-utils absolute_path ""
166166
'
167167

168168
test_expect_success 'real path rejects the empty string' '
169-
test_must_fail test-path-utils real_path ""
169+
test_must_fail test-tool path-utils real_path ""
170170
'
171171

172172
test_expect_success POSIX 'real path works on absolute paths 1' '
173173
nopath="hopefully-absent-path" &&
174-
test "/" = "$(test-path-utils real_path "/")" &&
175-
test "/$nopath" = "$(test-path-utils real_path "/$nopath")"
174+
test "/" = "$(test-tool path-utils real_path "/")" &&
175+
test "/$nopath" = "$(test-tool path-utils real_path "/$nopath")"
176176
'
177177

178178
test_expect_success 'real path works on absolute paths 2' '
179179
nopath="hopefully-absent-path" &&
180180
# Find an existing top-level directory for the remaining tests:
181181
d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") &&
182-
test "$d" = "$(test-path-utils real_path "$d")" &&
183-
test "$d/$nopath" = "$(test-path-utils real_path "$d/$nopath")"
182+
test "$d" = "$(test-tool path-utils real_path "$d")" &&
183+
test "$d/$nopath" = "$(test-tool path-utils real_path "$d/$nopath")"
184184
'
185185

186186
test_expect_success POSIX 'real path removes extra leading slashes' '
187187
nopath="hopefully-absent-path" &&
188-
test "/" = "$(test-path-utils real_path "///")" &&
189-
test "/$nopath" = "$(test-path-utils real_path "///$nopath")" &&
188+
test "/" = "$(test-tool path-utils real_path "///")" &&
189+
test "/$nopath" = "$(test-tool path-utils real_path "///$nopath")" &&
190190
# Find an existing top-level directory for the remaining tests:
191191
d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") &&
192-
test "$d" = "$(test-path-utils real_path "//$d")" &&
193-
test "$d/$nopath" = "$(test-path-utils real_path "//$d/$nopath")"
192+
test "$d" = "$(test-tool path-utils real_path "//$d")" &&
193+
test "$d/$nopath" = "$(test-tool path-utils real_path "//$d/$nopath")"
194194
'
195195

196196
test_expect_success 'real path removes other extra slashes' '
197197
nopath="hopefully-absent-path" &&
198198
# Find an existing top-level directory for the remaining tests:
199199
d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") &&
200-
test "$d" = "$(test-path-utils real_path "$d///")" &&
201-
test "$d/$nopath" = "$(test-path-utils real_path "$d///$nopath")"
200+
test "$d" = "$(test-tool path-utils real_path "$d///")" &&
201+
test "$d/$nopath" = "$(test-tool path-utils real_path "$d///$nopath")"
202202
'
203203

204204
test_expect_success SYMLINKS 'real path works on symlinks' '
@@ -209,35 +209,35 @@ test_expect_success SYMLINKS 'real path works on symlinks' '
209209
mkdir third &&
210210
dir="$(cd .git; pwd -P)" &&
211211
dir2=third/../second/other/.git &&
212-
test "$dir" = "$(test-path-utils real_path $dir2)" &&
212+
test "$dir" = "$(test-tool path-utils real_path $dir2)" &&
213213
file="$dir"/index &&
214-
test "$file" = "$(test-path-utils real_path $dir2/index)" &&
214+
test "$file" = "$(test-tool path-utils real_path $dir2/index)" &&
215215
basename=blub &&
216-
test "$dir/$basename" = "$(cd .git && test-path-utils real_path "$basename")" &&
216+
test "$dir/$basename" = "$(cd .git && test-tool path-utils real_path "$basename")" &&
217217
ln -s ../first/file .git/syml &&
218218
sym="$(cd first; pwd -P)"/file &&
219-
test "$sym" = "$(test-path-utils real_path "$dir2/syml")"
219+
test "$sym" = "$(test-tool path-utils real_path "$dir2/syml")"
220220
'
221221

222222
test_expect_success SYMLINKS 'prefix_path works with absolute paths to work tree symlinks' '
223223
ln -s target symlink &&
224-
test "$(test-path-utils prefix_path prefix "$(pwd)/symlink")" = "symlink"
224+
test "$(test-tool path-utils prefix_path prefix "$(pwd)/symlink")" = "symlink"
225225
'
226226

227227
test_expect_success 'prefix_path works with only absolute path to work tree' '
228228
echo "" >expected &&
229-
test-path-utils prefix_path prefix "$(pwd)" >actual &&
229+
test-tool path-utils prefix_path prefix "$(pwd)" >actual &&
230230
test_cmp expected actual
231231
'
232232

233233
test_expect_success 'prefix_path rejects absolute path to dir with same beginning as work tree' '
234-
test_must_fail test-path-utils prefix_path prefix "$(pwd)a"
234+
test_must_fail test-tool path-utils prefix_path prefix "$(pwd)a"
235235
'
236236

237237
test_expect_success SYMLINKS 'prefix_path works with absolute path to a symlink to work tree having same beginning as work tree' '
238238
git init repo &&
239239
ln -s repo repolink &&
240-
test "a" = "$(cd repo && test-path-utils prefix_path prefix "$(pwd)/../repolink/a")"
240+
test "a" = "$(cd repo && test-tool path-utils prefix_path prefix "$(pwd)/../repolink/a")"
241241
'
242242

243243
relative_path /foo/a/b/c/ /foo/a/b/ c/

t/t1501-work-tree.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ test_expect_success 'GIT_DIR set (1)' '
360360
(
361361
cd work &&
362362
GIT_DIR=../gitfile git rev-parse --git-common-dir >actual &&
363-
test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
363+
test-tool path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
364364
test_cmp expect actual
365365
)
366366
'
@@ -371,7 +371,7 @@ test_expect_success 'GIT_DIR set (2)' '
371371
(
372372
cd work &&
373373
GIT_DIR=../gitfile git rev-parse --git-common-dir >actual &&
374-
test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
374+
test-tool path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
375375
test_cmp expect actual
376376
)
377377
'
@@ -382,7 +382,7 @@ test_expect_success 'Auto discovery' '
382382
(
383383
cd work &&
384384
git rev-parse --git-common-dir >actual &&
385-
test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
385+
test-tool path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
386386
test_cmp expect actual &&
387387
echo haha >data1 &&
388388
git add data1 &&
@@ -400,7 +400,7 @@ test_expect_success '$GIT_DIR/common overrides core.worktree' '
400400
(
401401
cd work &&
402402
git rev-parse --git-common-dir >actual &&
403-
test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
403+
test-tool path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect &&
404404
test_cmp expect actual &&
405405
echo haha >data2 &&
406406
git add data2 &&

0 commit comments

Comments
 (0)