Skip to content

Commit 21386ed

Browse files
pks-tgitster
authored andcommitted
t: adapt test_readlink() to not use Perl
The `test_readlink()` helper function reads a symbolic link and returns the path it is pointing to. It is thus equivalent to the readlink(1) utility, which isn't available on all supported platforms. As such, it is implemented using Perl so that we can use it even on platforms where the shell utility isn't available. While using readlink(1) is not an option, what we can do is to implement the logic ourselves in our test-tool. Do so, which allows a bunch of tests to pass when Perl is not available. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 01486b5 commit 21386ed

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

t/helper/test-path-utils.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,19 @@ int cmd__path_utils(int argc, const char **argv)
323323
return 0;
324324
}
325325

326+
if (argc >= 2 && !strcmp(argv[1], "readlink")) {
327+
struct strbuf target = STRBUF_INIT;
328+
while (argc > 2) {
329+
if (strbuf_readlink(&target, argv[2], 0) < 0)
330+
die_errno("cannot read link at '%s'", argv[2]);
331+
puts(target.buf);
332+
argc--;
333+
argv++;
334+
}
335+
strbuf_release(&target);
336+
return 0;
337+
}
338+
326339
if (argc >= 2 && !strcmp(argv[1], "absolute_path")) {
327340
while (argc > 2) {
328341
puts(absolute_path(argv[2]));

t/test-lib-functions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1979,7 +1979,7 @@ test_remote_https_urls() {
19791979
# Print the destination of symlink(s) provided as arguments. Basically
19801980
# the same as the readlink command, but it's not available everywhere.
19811981
test_readlink () {
1982-
perl -le 'print readlink($_) for @ARGV' "$@"
1982+
test-tool path-utils readlink "$@"
19831983
}
19841984

19851985
# Set mtime to a fixed "magic" timestamp in mid February 2009, before we

0 commit comments

Comments
 (0)