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>
Nguyễn Thái Ngọc Duy committed
Mar 24, 2018 at 08:44 UTC
b8d5cf4f96f6e57ddc91dfcc530e47c878aff598
7 files changed
+40
-37
Makefile
+1
-1
@@ -669,6 +669,7 @@ TEST_BUILTINS_OBJS += test-match-trees.o
669
TEST_BUILTINS_OBJS += test-mergesort.o
670
TEST_BUILTINS_OBJS += test-mktemp.o
671
TEST_BUILTINS_OBJS += test-online-cpus.o
672
+TEST_BUILTINS_OBJS += test-path-utils.o
673
TEST_BUILTINS_OBJS += test-sha1.o
674
675
TEST_PROGRAMS_NEED_X += test-dump-fsmonitor
@@ -676,7 +677,6 @@ TEST_PROGRAMS_NEED_X += test-dump-untracked-cache
677
TEST_PROGRAMS_NEED_X += test-fake-ssh
678
TEST_PROGRAMS_NEED_X += test-line-buffer
679
TEST_PROGRAMS_NEED_X += test-parse-options
679
-TEST_PROGRAMS_NEED_X += test-path-utils
680
TEST_PROGRAMS_NEED_X += test-prio-queue
681
TEST_PROGRAMS_NEED_X += test-read-cache
682
TEST_PROGRAMS_NEED_X += test-write-cache
t/helper/test-path-utils.c
+2
-1
@@ -1,3 +1,4 @@
1
+#include "test-tool.h"
2
#include "cache.h"
3
#include "string-list.h"
4
@@ -170,7 +171,7 @@ static struct test_data dirname_data[] = {
171
{ NULL, NULL }
172
};
173
173
-int cmd_main(int argc, const char **argv)
174
+int cmd__path_utils(int argc, const char **argv)
175
{
176
if (argc == 3 && !strcmp(argv[1], "normalize_path_copy")) {
177
char *buf = xmallocz(strlen(argv[2]));
t/helper/test-tool.c
+1
@@ -24,6 +24,7 @@ static struct test_cmd cmds[] = {
24
{ "mergesort", cmd__mergesort },
25
{ "mktemp", cmd__mktemp },
26
{ "online-cpus", cmd__online_cpus },
27
+ { "path-utils", cmd__path_utils },
28
{ "sha1", cmd__sha1 },
29
};
30
t/helper/test-tool.h
+1
@@ -18,6 +18,7 @@ int cmd__match_trees(int argc, const char **argv);
18
int cmd__mergesort(int argc, const char **argv);
19
int cmd__mktemp(int argc, const char **argv);
20
int cmd__online_cpus(int argc, const char **argv);
21
+int cmd__path_utils(int argc, const char **argv);
22
int cmd__sha1(int argc, const char **argv);
23
24
#endif
t/lib-git-p4.sh
+1
-1
@@ -39,7 +39,7 @@ native_path () {
39
then
40
path=$(cygpath --windows "$path")
41
else
42
- path=$(test-path-utils real_path "$path")
42
+ path=$(test-tool path-utils real_path "$path")
43
fi &&
44
echo "$path"
45
}
t/t0060-path-utils.sh
+30
-30
@@ -8,15 +8,15 @@ test_description='Test various path utilities'
8
. ./test-lib.sh
9
10
norm_path() {
11
- expected=$(test-path-utils print_path "$2")
11
+ expected=$(test-tool path-utils print_path "$2")
12
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'"
14
}
15
16
relative_path() {
17
- expected=$(test-path-utils print_path "$3")
17
+ expected=$(test-tool path-utils print_path "$3")
18
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'"
20
}
21
22
test_submodule_relative_url() {
@@ -37,7 +37,7 @@ test_git_path() {
37
# On Windows, we are using MSYS's bash, which mangles the paths.
38
# Absolute paths are anchored at the MSYS installation directory,
39
# 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)
41
# Account for the trailing LF:
42
if test $rootoff = 2; then
43
rootoff= # we are on Unix
@@ -46,7 +46,7 @@ else
46
# In MSYS2, the root directory "/" is translated into a Windows
47
# directory *with* trailing slash. Let's test for that and adjust
48
# our expected longest ancestor length accordingly.
49
- case "$(test-path-utils print_path /)" in
49
+ case "$(test-tool path-utils print_path /)" in
50
*/) rootslash=1;;
51
*) rootslash=0;;
52
esac
@@ -61,7 +61,7 @@ ancestor() {
61
expected=$(($expected+$rootoff))
62
fi
63
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') &&
65
test \"\$actual\" = '$expected'"
66
}
67
@@ -77,8 +77,8 @@ case $(uname -s) in
77
;;
78
esac
79
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'
82
83
norm_path "" ""
84
norm_path . ""
@@ -157,48 +157,48 @@ ancestor /foo/bar /foo:/bar 4
157
ancestor /foo/bar /bar -1
158
159
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 \
161
c:/msysgit/libexec//git-core libexec/git-core)
162
'
163
164
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 ""
166
'
167
168
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 ""
170
'
171
172
test_expect_success POSIX 'real path works on absolute paths 1' '
173
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")"
176
'
177
178
test_expect_success 'real path works on absolute paths 2' '
179
nopath="hopefully-absent-path" &&
180
# Find an existing top-level directory for the remaining tests:
181
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")"
184
'
185
186
test_expect_success POSIX 'real path removes extra leading slashes' '
187
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")" &&
190
# Find an existing top-level directory for the remaining tests:
191
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")"
194
'
195
196
test_expect_success 'real path removes other extra slashes' '
197
nopath="hopefully-absent-path" &&
198
# Find an existing top-level directory for the remaining tests:
199
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")"
202
'
203
204
test_expect_success SYMLINKS 'real path works on symlinks' '
@@ -209,35 +209,35 @@ test_expect_success SYMLINKS 'real path works on symlinks' '
209
mkdir third &&
210
dir="$(cd .git; pwd -P)" &&
211
dir2=third/../second/other/.git &&
212
- test "$dir" = "$(test-path-utils real_path $dir2)" &&
212
+ test "$dir" = "$(test-tool path-utils real_path $dir2)" &&
213
file="$dir"/index &&
214
- test "$file" = "$(test-path-utils real_path $dir2/index)" &&
214
+ test "$file" = "$(test-tool path-utils real_path $dir2/index)" &&
215
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")" &&
217
ln -s ../first/file .git/syml &&
218
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")"
220
'
221
222
test_expect_success SYMLINKS 'prefix_path works with absolute paths to work tree symlinks' '
223
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"
225
'
226
227
test_expect_success 'prefix_path works with only absolute path to work tree' '
228
echo "" >expected &&
229
- test-path-utils prefix_path prefix "$(pwd)" >actual &&
229
+ test-tool path-utils prefix_path prefix "$(pwd)" >actual &&
230
test_cmp expected actual
231
'
232
233
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"
235
'
236
237
test_expect_success SYMLINKS 'prefix_path works with absolute path to a symlink to work tree having same beginning as work tree' '
238
git init repo &&
239
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")"
241
'
242
243
relative_path /foo/a/b/c/ /foo/a/b/ c/
t/t1501-work-tree.sh
+4
-4
@@ -360,7 +360,7 @@ test_expect_success 'GIT_DIR set (1)' '
360
(
361
cd work &&
362
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 &&
364
test_cmp expect actual
365
)
366
'
@@ -371,7 +371,7 @@ test_expect_success 'GIT_DIR set (2)' '
371
(
372
cd work &&
373
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 &&
375
test_cmp expect actual
376
)
377
'
@@ -382,7 +382,7 @@ test_expect_success 'Auto discovery' '
382
(
383
cd work &&
384
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 &&
386
test_cmp expect actual &&
387
echo haha >data1 &&
388
git add data1 &&
@@ -400,7 +400,7 @@ test_expect_success '$GIT_DIR/common overrides core.worktree' '
400
(
401
cd work &&
402
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 &&
404
test_cmp expect actual &&
405
echo haha >data2 &&
406
git add data2 &&