X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fgcf2.t;h=d12a4420b5c01099bbb0b8bbd0ef8d94460afb8a;hb=2f8d15b1170b137a0512a4f3163b236a5dcbf0b8;hp=9056b340315bc8e5439b9e897e2b46c52b747b8c;hpb=08259ae3cbc859aafa2a4bd79689b82b121ebf76;p=public-inbox.git diff --git a/t/gcf2.t b/t/gcf2.t index 9056b340..d12a4420 100644 --- a/t/gcf2.t +++ b/t/gcf2.t @@ -1,5 +1,5 @@ #!perl -w -# Copyright (C) 2020 all contributors +# Copyright (C) 2020-2021 all contributors # License: AGPL-3.0+ use strict; use PublicInbox::TestCommon; @@ -76,55 +76,53 @@ SKIP: { } open my $fh, '+>', undef or BAIL_OUT "open: $!"; - my $fd = fileno($fh); $fh->autoflush(1); - $gcf2->cat_oid($fd, 'invalid'); + ok(!$gcf2->cat_oid(fileno($fh), 'invalid'), 'invalid fails'); seek($fh, 0, SEEK_SET) or BAIL_OUT "seek: $!"; - is(do { local $/; <$fh> }, "invalid missing\n", 'got missing message'); + is(do { local $/; <$fh> }, '', 'nothing written'); + open $fh, '+>', undef or BAIL_OUT "open: $!"; + ok(!$gcf2->cat_oid(fileno($fh), '0'x40), 'z40 fails'); seek($fh, 0, SEEK_SET) or BAIL_OUT "seek: $!"; - $gcf2->cat_oid($fd, '0'x40); - seek($fh, 0, SEEK_SET) or BAIL_OUT "seek: $!"; - is(do { local $/; <$fh> }, ('0'x40)." missing\n", - 'got missing message for 0x40'); + is(do { local $/; <$fh> }, '', 'nothing written for z40'); - seek($fh, 0, SEEK_SET) or BAIL_OUT "seek: $!"; - $gcf2->cat_oid($fd, $COPYING); - my $buf; + open $fh, '+>', undef or BAIL_OUT "open: $!"; my $ck_copying = sub { my ($desc) = @_; seek($fh, 0, SEEK_SET) or BAIL_OUT "seek: $!"; - is(<$fh>, "$COPYING blob 34520\n", 'got expected header'); - $buf = do { local $/; <$fh> }; + is(<$fh>, "$COPYING blob 34520\n", "got expected header $desc"); + my $buf = do { local $/; <$fh> }; is(chop($buf), "\n", 'got trailing \\n'); is($buf, $agpl, "AGPL matches ($desc)"); }; + ok($gcf2->cat_oid(fileno($fh), $COPYING), 'cat_oid normal'); $ck_copying->('regular file'); $gcf2 = PublicInbox::Gcf2::new(); $gcf2->add_alternate("$tmpdir/objects"); - $ck_copying->('alternates respected'); + open $fh, '+>', undef or BAIL_OUT "open: $!"; + ok($gcf2->cat_oid(fileno($fh), $COPYING), 'cat_oid alternate'); + $ck_copying->('alternates after reopen'); - $^O eq 'linux' or skip('pipe tests are Linux-only', 12); - my $size = -s $fh; + $^O eq 'linux' or skip('pipe tests are Linux-only', 14); for my $blk (1, 0) { my ($r, $w); pipe($r, $w) or BAIL_OUT $!; fcntl($w, 1031, 4096) or - skip('Linux too old for F_SETPIPE_SZ', 12); + skip('Linux too old for F_SETPIPE_SZ', 14); $w->blocking($blk); seek($fh, 0, SEEK_SET) or BAIL_OUT "seek: $!"; truncate($fh, 0) or BAIL_OUT "truncate: $!"; - defined(my $pid = fork) or BAIL_OUT "fork: $!"; + my $pid = fork // BAIL_OUT "fork: $!"; if ($pid == 0) { close $w; tick; # wait for parent to block on writev - $buf = do { local $/; <$r> }; + my $buf = do { local $/; <$r> }; print $fh $buf or _exit(1); _exit(0); } - $gcf2->cat_oid(fileno($w), $COPYING); + ok($gcf2->cat_oid(fileno($w), $COPYING), "cat blocking=$blk"); close $w or BAIL_OUT "close: $!"; is(waitpid($pid, 0), $pid, 'child exited'); is($?, 0, 'no error in child');