diff mbox series

[04/20] t: adapt `test_copy_bytes()` to not use Perl

Message ID 20250320-b4-pks-t-perlless-v1-4-b1eefe27ac55@pks.im (mailing list archive)
State Superseded
Headers show
Series t: drop Perl as a mandatory prerequisite | expand

Commit Message

Patrick Steinhardt March 20, 2025, 9:35 a.m. UTC
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 <ps@pks.im>
---
 t/test-lib-functions.sh | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

Comments

Karthik Nayak March 21, 2025, 9:56 a.m. UTC | #1
Patrick Steinhardt <ps@pks.im> writes:

> 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 <ps@pks.im>
> ---
>  t/test-lib-functions.sh | 12 +-----------
>  1 file changed, 1 insertion(+), 11 deletions(-)
>
> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> index 377f08a1428..c4b4d3a4c7f 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
>  }
>

Really nice!

>  # run "$@" inside a non-git directory
>
> --
> 2.49.0.472.ge94155a9ec.dirty
diff mbox series

Patch

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 377f08a1428..c4b4d3a4c7f 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