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

index 377f08a1428174249c198336df698d24f8eb7a90..c4b4d3a4c7fd6aacd700f87abb6d0b9724449ae2 100644 (file)
@@ -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