]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t: adapt `test_readlink()` to not use Perl
authorPatrick Steinhardt <ps@pks.im>
Thu, 3 Apr 2025 05:05:56 +0000 (07:05 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 7 Apr 2025 21:47:37 +0000 (14:47 -0700)
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>
t/helper/test-path-utils.c
t/test-lib-functions.sh

index 72ac8d1b1b011de48ddc62dfae4b21f4132559a0..54d9ba98c0e89b29b3a9fbcf08b9b7a2251edd1a 100644 (file)
@@ -323,6 +323,19 @@ int cmd__path_utils(int argc, const char **argv)
                return 0;
        }
 
+       if (argc >= 2 && !strcmp(argv[1], "readlink")) {
+               struct strbuf target = STRBUF_INIT;
+               while (argc > 2) {
+                       if (strbuf_readlink(&target, argv[2], 0) < 0)
+                               die_errno("cannot read link at '%s'", argv[2]);
+                       puts(target.buf);
+                       argc--;
+                       argv++;
+               }
+               strbuf_release(&target);
+               return 0;
+       }
+
        if (argc >= 2 && !strcmp(argv[1], "absolute_path")) {
                while (argc > 2) {
                        puts(absolute_path(argv[2]));
index c4b4d3a4c7fd6aacd700f87abb6d0b9724449ae2..bff8c4d1b41868e0ec7a3b4cb938d08389f63b8e 100644 (file)
@@ -1979,7 +1979,7 @@ test_remote_https_urls() {
 # Print the destination of symlink(s) provided as arguments. Basically
 # the same as the readlink command, but it's not available everywhere.
 test_readlink () {
-       perl -le 'print readlink($_) for @ARGV' "$@"
+       test-tool path-utils readlink "$@"
 }
 
 # Set mtime to a fixed "magic" timestamp in mid February 2009, before we