]> Sergey Matveev's repositories - public-inbox.git/blob - t/lei-sigpipe.t
www: drop --subject from "git send-email" instructions
[public-inbox.git] / t / lei-sigpipe.t
1 #!perl -w
2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict;
5 use v5.10.1;
6 use PublicInbox::TestCommon;
7 use POSIX qw(WTERMSIG WIFSIGNALED SIGPIPE);
8 use PublicInbox::OnDestroy;
9
10 # undo systemd (and similar) ignoring SIGPIPE, since lei expects to be run
11 # from an interactive terminal:
12 # https://public-inbox.org/meta/20220227080422.gyqowrxomzu6gyin@sourcephile.fr/
13 my $oldSIGPIPE = $SIG{PIPE};
14 $SIG{PIPE} = 'DEFAULT';
15 my $cleanup = PublicInbox::OnDestroy->new($$, sub {
16         $SIG{PIPE} = $oldSIGPIPE;
17 });
18
19 test_lei(sub {
20         my $f = "$ENV{HOME}/big.eml";
21         my $imported;
22         for my $out ([], [qw(-f mboxcl2)], [qw(-f text)]) {
23                 pipe(my ($r, $w)) or BAIL_OUT $!;
24                 my $size = 65536;
25                 if ($^O eq 'linux' && fcntl($w, 1031, 4096)) {
26                         $size = 4096;
27                 }
28                 unless (-f $f) {
29                         open my $fh, '>', $f or xbail "open $f: $!";
30                         print $fh <<'EOM' or xbail;
31 From: big@example.com
32 Message-ID: <big@example.com>
33 EOM
34                         print $fh 'Subject:';
35                         print $fh (' '.('x' x 72)."\n") x (($size / 73) + 1);
36                         print $fh "\nbody\n";
37                         close $fh or xbail "close: $!";
38                 }
39
40                 lei_ok(qw(import), $f) if $imported++ == 0;
41                 open my $errfh, '+>>', "$ENV{HOME}/stderr.log" or xbail $!;
42                 my $opt = { run_mode => 0, 2 => $errfh, 1 => $w };
43                 my $cmd = [qw(lei q -q -t), @$out, 'z:1..'];
44                 my $tp = start_script($cmd, undef, $opt);
45                 close $w;
46                 vec(my $rvec = '', fileno($r), 1) = 1;
47                 if (!select($rvec, undef, undef, 30)) {
48                         seek($errfh, 0, 0) or xbail $!;
49                         my $s = do { local $/; <$errfh> };
50                         xbail "lei q had no output after 30s, stderr=$s";
51                 }
52                 is(sysread($r, my $buf, 1), 1, 'read one byte');
53                 close $r; # trigger SIGPIPE
54                 $tp->join;
55                 ok(WIFSIGNALED($?), "signaled @$out");
56                 is(WTERMSIG($?), SIGPIPE, "got SIGPIPE @$out");
57                 seek($errfh, 0, 0) or xbail $!;
58                 my $s = do { local $/; <$errfh> };
59                 is($s, '', "quiet after sigpipe @$out");
60         }
61 });
62
63 done_testing;