t1006: ensure cat-file info isn't buffered by default

While working on buffering changes to `git cat-file' in a separate patch, I inadvertently made the output of --batch-check and the `info' command of --batch-command buffered as if opt->buffer_output is turned on by default. Buffering by default breaks some 3rd-party Perl scripts using cat-file, but this breakage was not detected anywhere in our test suite. Add a small Perl snippet to test this problem since (AFAIK) other equivalent ways to test this behavior from Bourne shell and/or awk would require racy sleeps, non-portable FIFOs or tedious C code. Signed-off-by: Eric Wong <e@80x24.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Wong committed Jun 18, 2024 at 21:30 UTC 75daa42ddf5ec4755eaec47909f30cbd84719e88
1 file changed +30
t/t1006-cat-file.sh
+30
@@ -1294,4 +1294,34 @@ test_expect_success 'batch-command flush without --buffer' '
1294 grep "^fatal:.*flush is only for --buffer mode.*" err
1295 '
1296
1297 +script='
1298 +use warnings;
1299 +use strict;
1300 +use IPC::Open2;
1301 +my ($opt, $oid, $expect, @pfx) = @ARGV;
1302 +my @cmd = (qw(git cat-file), $opt);
1303 +my $pid = open2(my $out, my $in, @cmd) or die "open2: @cmd";
1304 +print $in @pfx, $oid, "\n" or die "print $!";
1305 +my $rvec = "";
1306 +vec($rvec, fileno($out), 1) = 1;
1307 +select($rvec, undef, undef, 30) or die "no response to `@pfx $oid` from @cmd";
1308 +my $info = <$out>;
1309 +chop($info) eq "\n" or die "no LF";
1310 +$info eq $expect or die "`$info` != `$expect`";
1311 +close $in or die "close in $!";
1312 +close $out or die "close out $!";
1313 +waitpid $pid, 0;
1314 +$? == 0 or die "\$?=$?";
1315 +'
1316 +
1317 +expect="$hello_oid blob $hello_size"
1318 +
1319 +test_expect_success PERL '--batch-check is unbuffered by default' '
1320 + perl -e "$script" -- --batch-check $hello_oid "$expect"
1321 +'
1322 +
1323 +test_expect_success PERL '--batch-command info is unbuffered by default' '
1324 + perl -e "$script" -- --batch-command $hello_oid "$expect" "info "
1325 +'
1326 +
1327 test_done