X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Flei-sigpipe.t;h=55c208e2740c039327f26855964c94e12bcb5c5e;hb=f1e4e14793d155ea7d6ed7a6858b668e97c7e5d8;hp=f84d6d22ec4d410f77ba9b57ad8c61331ba3a13f;hpb=420fa1eac8cf0c73b6b0512c32206dc0b904dd45;p=public-inbox.git
diff --git a/t/lei-sigpipe.t b/t/lei-sigpipe.t
index f84d6d22..55c208e2 100644
--- a/t/lei-sigpipe.t
+++ b/t/lei-sigpipe.t
@@ -1,14 +1,25 @@
#!perl -w
-# Copyright (C) 2021 all contributors
+# Copyright (C) all contributors
# License: AGPL-3.0+
use strict;
use v5.10.1;
use PublicInbox::TestCommon;
use POSIX qw(WTERMSIG WIFSIGNALED SIGPIPE);
+use PublicInbox::OnDestroy;
+
+# undo systemd (and similar) ignoring SIGPIPE, since lei expects to be run
+# from an interactive terminal:
+# https://public-inbox.org/meta/20220227080422.gyqowrxomzu6gyin@sourcephile.fr/
+my $oldSIGPIPE = $SIG{PIPE};
+$SIG{PIPE} = 'DEFAULT';
+my $cleanup = PublicInbox::OnDestroy->new($$, sub {
+ $SIG{PIPE} = $oldSIGPIPE;
+});
+
test_lei(sub {
my $f = "$ENV{HOME}/big.eml";
my $imported;
- for my $out ([], [qw(-f mboxcl2)]) {
+ for my $out ([], [qw(-f mboxcl2)], [qw(-f text)]) {
pipe(my ($r, $w)) or BAIL_OUT $!;
my $size = 65536;
if ($^O eq 'linux' && fcntl($w, 1031, 4096)) {
@@ -27,16 +38,25 @@ EOM
}
lei_ok(qw(import), $f) if $imported++ == 0;
- open my $errfh, '>>', "$ENV{HOME}/stderr.log" or xbail $!;
+ open my $errfh, '+>>', "$ENV{HOME}/stderr.log" or xbail $!;
my $opt = { run_mode => 0, 2 => $errfh, 1 => $w };
my $cmd = [qw(lei q -q -t), @$out, 'z:1..'];
my $tp = start_script($cmd, undef, $opt);
close $w;
+ vec(my $rvec = '', fileno($r), 1) = 1;
+ if (!select($rvec, undef, undef, 30)) {
+ seek($errfh, 0, 0) or xbail $!;
+ my $s = do { local $/; <$errfh> };
+ xbail "lei q had no output after 30s, stderr=$s";
+ }
is(sysread($r, my $buf, 1), 1, 'read one byte');
close $r; # trigger SIGPIPE
$tp->join;
ok(WIFSIGNALED($?), "signaled @$out");
is(WTERMSIG($?), SIGPIPE, "got SIGPIPE @$out");
+ seek($errfh, 0, 0) or xbail $!;
+ my $s = do { local $/; <$errfh> };
+ is($s, '', "quiet after sigpipe @$out");
}
});