]> Sergey Matveev's repositories - public-inbox.git/blob - xt/lei-sigpipe.t
lei q: emit progress and counting via PktOp
[public-inbox.git] / xt / 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 Test::More;
7 use PublicInbox::TestCommon;
8 use POSIX qw(WTERMSIG WIFSIGNALED SIGPIPE);
9 require_mods(qw(json DBD::SQLite Search::Xapian));
10 # XXX this needs an already configured lei instance with many messages
11
12 my $do_test = sub {
13         my $env = shift // {};
14         for my $out ([], [qw(-f mboxcl2)]) {
15                 pipe(my ($r, $w)) or BAIL_OUT $!;
16                 open my $err, '+>', undef or BAIL_OUT $!;
17                 my $opt = { run_mode => 0, 1 => $w, 2 => $err };
18                 my $cmd = [qw(lei q -q -t), @$out, 'bytes:1..'];
19                 my $tp = start_script($cmd, $env, $opt);
20                 close $w;
21                 sysread($r, my $buf, 1);
22                 close $r; # trigger SIGPIPE
23                 $tp->join;
24                 ok(WIFSIGNALED($?), "signaled @$out");
25                 is(WTERMSIG($?), SIGPIPE, "got SIGPIPE @$out");
26                 seek($err, 0, 0);
27                 my @err = grep(!m{mkdir /dev/null\b}, <$err>);
28                 is_deeply(\@err, [], "no errors @$out");
29         }
30 };
31
32 $do_test->();
33 $do_test->({XDG_RUNTIME_DIR => '/dev/null'});
34
35 done_testing;