]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/lei_to_mail.t
lei_input: support compressed mboxes
[public-inbox.git] / t / lei_to_mail.t
index 77e9902ef32c6509b688b41b752ccbb7086f7203..75314add027d33ebe8e1ced8e87a46d60c8ae71a 100644 (file)
@@ -6,8 +6,8 @@ use v5.10.1;
 use Test::More;
 use PublicInbox::TestCommon;
 use PublicInbox::Eml;
-use Fcntl qw(SEEK_SET);
-use PublicInbox::Spawn qw(popen_rd which);
+use Fcntl qw(SEEK_SET O_RDONLY O_NONBLOCK);
+use PublicInbox::Spawn qw(popen_rd);
 use List::Util qw(shuffle);
 require_mods(qw(DBD::SQLite));
 require PublicInbox::MdirReader;
@@ -28,7 +28,7 @@ for my $mbox (@MBOX) {
        my $s = $cb->(PublicInbox::Eml->new($from), $smsg);
        is(substr($$s, -1, 1), "\n", "trailing LF in normal $mbox");
        my $eml = PublicInbox::Eml->new($s);
-       is($eml->header('Status'), 'OR', "Status: set by $m");
+       is($eml->header('Status'), 'RO', "Status: set by $m");
        is($eml->header('X-Status'), 'AF', "X-Status: set by $m");
        if ($mbox eq 'mboxcl2') {
                like($eml->body_raw, qr/^From /, "From not escaped $m");
@@ -101,9 +101,9 @@ my $wcb_get = sub {
                my $dup = Storable::thaw(Storable::freeze($l2m));
                is_deeply($dup, $l2m, "$fmt round-trips through storable");
        }
-       my $zpipe = $l2m->pre_augment($lei);
+       $l2m->pre_augment($lei);
        $l2m->do_augment($lei);
-       $l2m->post_augment($lei, $zpipe);
+       $l2m->post_augment($lei);
        $l2m->write_cb($lei);
 };
 
@@ -130,7 +130,7 @@ my $orig = do {
 };
 
 test_lei(sub {
-       ok(lei(qw(import -f), $mbox, $fn), 'imported mbox');
+       ok(lei(qw(import -F), $mbox, $fn), 'imported mbox');
        ok(lei(qw(q s:x)), 'lei q works') or diag $lei_err;
        my $res = json_utf8->decode($lei_out);
        my $x = $res->[0];
@@ -139,8 +139,18 @@ test_lei(sub {
        is($res->[1], undef, 'only one result');
 });
 
-for my $zsfx (qw(gz bz2 xz)) { # XXX should we support zst, zz, lzo, lzma?
-       my $zsfx2cmd = PublicInbox::LeiToMail->can('zsfx2cmd');
+test_lei(sub {
+       lei_ok('import', "$mbox:$fn", \'imported mbox:/path') or diag $lei_err;
+       lei_ok(qw(q s:x), \'lei q works') or diag $lei_err;
+       my $res = json_utf8->decode($lei_out);
+       my $x = $res->[0];
+       is($x->{'s'}, 'x', 'subject imported') or diag $lei_out;
+       is_deeply($x->{'kw'}, ['seen'], 'kw imported') or diag $lei_out;
+       is($res->[1], undef, 'only one result');
+});
+
+my $zsfx2cmd = PublicInbox::MboxReader->can('zsfx2cmd');
+for my $zsfx (qw(gz bz2 xz)) {
        SKIP: {
                my $cmd = eval { $zsfx2cmd->($zsfx, 0, $lei) };
                skip $@, 3 if $@;
@@ -232,11 +242,12 @@ SKIP: { # FIFO support
        use POSIX qw(mkfifo);
        my $fn = "$tmpdir/fifo";
        mkfifo($fn, 0600) or skip("mkfifo not supported: $!", 1);
-       my $cat = popen_rd([which('cat'), $fn]);
+       sysopen(my $cat, $fn, O_RDONLY|O_NONBLOCK) or BAIL_OUT $!;
        my $wcb = $wcb_get->('mboxo', $fn);
        $wcb->(\(my $x = $buf), $deadbeef);
        $commit->($wcb);
        my $cmp = '';
+       $cat->blocking(1);
        PublicInbox::MboxReader->mboxo($cat, sub { $cmp .= $as_orig->(@_) });
        is($cmp, $buf, 'message written to FIFO');
 }