]> Sergey Matveev's repositories - public-inbox.git/blob - t/lei-sigpipe.t
d9738b07bd8e5ddce780e8125b1207a1686cc9ab
[public-inbox.git] / t / lei-sigpipe.t
1 #!perl -w
2 # Copyright (C) 2021 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 test_lei(sub {
9         my $f = "$ENV{HOME}/big.eml";
10         my $imported;
11         for my $out ([], [qw(-f mboxcl2)], [qw(-f text)]) {
12                 pipe(my ($r, $w)) or BAIL_OUT $!;
13                 my $size = 65536;
14                 if ($^O eq 'linux' && fcntl($w, 1031, 4096)) {
15                         $size = 4096;
16                 }
17                 unless (-f $f) {
18                         open my $fh, '>', $f or xbail "open $f: $!";
19                         print $fh <<'EOM' or xbail;
20 From: big@example.com
21 Message-ID: <big@example.com>
22 EOM
23                         print $fh 'Subject:';
24                         print $fh (' '.('x' x 72)."\n") x (($size / 73) + 1);
25                         print $fh "\nbody\n";
26                         close $fh or xbail "close: $!";
27                 }
28
29                 lei_ok(qw(import), $f) if $imported++ == 0;
30                 open my $errfh, '+>', "$ENV{HOME}/stderr.log" or xbail $!;
31                 my $opt = { run_mode => 0, 2 => $errfh, 1 => $w };
32                 my $cmd = [qw(lei q -q -t), @$out, 'z:1..'];
33                 my $tp = start_script($cmd, undef, $opt);
34                 close $w;
35                 is(sysread($r, my $buf, 1), 1, 'read one byte');
36                 close $r; # trigger SIGPIPE
37                 $tp->join;
38                 ok(WIFSIGNALED($?), "signaled @$out");
39                 is(WTERMSIG($?), SIGPIPE, "got SIGPIPE @$out");
40                 seek($errfh, 0, 0) or xbail $!;
41                 my $s = do { local $/; <$errfh> };
42                 is($s, '', "quiet after sigpipe @$out");
43         }
44 });
45
46 done_testing;