From 2df6710097cf7abe07e4e3b42955cc881ca7aa22 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 3 Apr 2025 07:05:54 +0200 Subject: t: adapt character translation helpers to not use Perl We have a couple of helper functions that translate characters, e.g. from LF to NUL or NUL to 'Q' and vice versa. These helpers use Perl scripts, but they can be trivially adapted to instead use tr(1). Note that one specialty here is the handling of NUL characters in tr(1), which historically wasn't implemented correctly on all platforms. But quoting tr(1p): It was considered that automatically stripping NUL characters from the input was not correct functionality. However, the removal of -n in a later proposal does not remove the requirement that tr correctly process NUL characters in its input stream. So when tr(1) is implemented following the POSIX standard then it is expected to handle the transliteration of NUL just fine. Refactor the helpers accordingly, which allows a bunch of tests to pass when Perl is not available. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- t/test-lib-functions.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 't/test-lib-functions.sh') diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 79377bc0fc..377f08a142 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -88,15 +88,15 @@ test_decode_color () { } lf_to_nul () { - perl -pe 'y/\012/\000/' + tr '\012' '\000' } nul_to_q () { - perl -pe 'y/\000/Q/' + tr '\000' 'Q' } q_to_nul () { - perl -pe 'y/Q/\000/' + tr 'Q' '\000' } q_to_cr () { -- cgit v1.2.3 From 01486b5de886af06c5bbfb097736ec97b86bacda Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 3 Apr 2025 07:05:55 +0200 Subject: t: adapt `test_copy_bytes()` to not use Perl The `test_copy_bytes()` helper function copies up to N bytes from stdin to stdout. This is implemented using Perl, but it can be trivially adapted to instead use dd(1). Refactor the helper accordingly, which allows a bunch of tests to pass when Perl is not available. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- t/test-lib-functions.sh | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 't/test-lib-functions.sh') diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 377f08a142..c4b4d3a4c7 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -1640,17 +1640,7 @@ test_match_signal () { # Read up to "$1" bytes (or to EOF) from stdin and write them to stdout. test_copy_bytes () { - perl -e ' - my $len = $ARGV[1]; - while ($len > 0) { - my $s; - my $nread = sysread(STDIN, $s, $len); - die "cannot read: $!" unless defined($nread); - last unless $nread; - print $s; - $len -= $nread; - } - ' - "$1" + dd ibs=1 count="$1" 2>/dev/null } # run "$@" inside a non-git directory -- cgit v1.2.3 From 21386ed6ebde7a29de5a41639a714cecf69191e3 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 3 Apr 2025 07:05:56 +0200 Subject: 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 Signed-off-by: Junio C Hamano --- t/helper/test-path-utils.c | 13 +++++++++++++ t/test-lib-functions.sh | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 't/test-lib-functions.sh') diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c index 72ac8d1b1b..54d9ba98c0 100644 --- a/t/helper/test-path-utils.c +++ b/t/helper/test-path-utils.c @@ -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])); diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index c4b4d3a4c7..bff8c4d1b4 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -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 -- cgit v1.2.3