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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Apr 3, 2025 at 07:05 UTC 21386ed6ebde7a29de5a41639a714cecf69191e3
2 files changed +14 -1
t/helper/test-path-utils.c
+13
@@ -323,6 +323,19 @@ int cmd__path_utils(int argc, const char **argv)
323 return 0;
324 }
325
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 +
339 if (argc >= 2 && !strcmp(argv[1], "absolute_path")) {
340 while (argc > 2) {
341 puts(absolute_path(argv[2]));
t/test-lib-functions.sh
+1 -1
@@ -1979,7 +1979,7 @@ test_remote_https_urls() {
1979 # Print the destination of symlink(s) provided as arguments. Basically
1980 # the same as the readlink command, but it's not available everywhere.
1981 test_readlink () {
1982 - perl -le 'print readlink($_) for @ARGV' "$@"
1982 + test-tool path-utils readlink "$@"
1983 }
1984
1985 # Set mtime to a fixed "magic" timestamp in mid February 2009, before we