X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Flei_to_mail.t;h=e8958c64c46c73b6ae38feeef8718c2b7bd9e2f3;hb=4eee5af6011cc8cdefb66c9729952c7eff5c0b0b;hp=7898cc48396c55a01bca352a495a2fb1cc9a223f;hpb=cf7c27cadd9ce7800beedc72513cf12fda77420f;p=public-inbox.git diff --git a/t/lei_to_mail.t b/t/lei_to_mail.t index 7898cc48..e8958c64 100644 --- a/t/lei_to_mail.t +++ b/t/lei_to_mail.t @@ -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"); @@ -75,7 +75,7 @@ for my $mbox (@MBOX) { my ($tmpdir, $for_destroy) = tmpdir(); local $ENV{TMPDIR} = $tmpdir; open my $err, '>>', "$tmpdir/lei.err" or BAIL_OUT $!; -my $lei = bless { 2 => $err }, 'PublicInbox::LEI'; +my $lei = bless { 2 => $err, cmd => 'test' }, 'PublicInbox::LEI'; my $commit = sub { $_[0] = undef; # wcb delete $lei->{1}; @@ -90,7 +90,7 @@ my $fn = "$tmpdir/x.mbox"; my ($mbox) = shuffle(@MBOX); # pick one, shouldn't matter my $wcb_get = sub { my ($fmt, $dst) = @_; - delete $lei->{dedupe}; + delete $lei->{dedupe}; # to be recreated $lei->{ovv} = bless { fmt => $fmt, dst => $dst @@ -119,19 +119,18 @@ my $orig = do { like($raw, qr/^blah\n/sm, 'wrote content'); unlink $fn or BAIL_OUT $!; - local $lei->{opt} = { jobs => 2 }; $wcb = $wcb_get->($mbox, $fn); ok(-f $fn && !-s _, 'truncated mbox destination'); $wcb->(\($dup = $buf), $deadbeef); $commit->($wcb); open $fh, '<', $fn or BAIL_OUT $!; - is(do { local $/; <$fh> }, $raw, 'jobs > 1'); + is(do { local $/; <$fh> }, $raw, 'wrote identical content'); $raw; }; -test_lei(sub { - ok(lei(qw(import -F), $mbox, $fn), 'imported mbox'); - ok(lei(qw(q s:x)), 'lei q works') or diag $lei_err; +test_lei({tmpdir => "$tmpdir/using -F"}, sub { + lei_ok(qw(import -F), $mbox, $fn, \'imported mbox'); + 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; @@ -139,7 +138,7 @@ test_lei(sub { is($res->[1], undef, 'only one result'); }); -test_lei(sub { +test_lei({tmpdir => "$tmpdir/using TYPE: prefix"}, 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); @@ -149,8 +148,8 @@ 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'); +my $zsfx2cmd = PublicInbox::MboxReader->can('zsfx2cmd'); +for my $zsfx (qw(gz bz2 xz)) { SKIP: { my $cmd = eval { $zsfx2cmd->($zsfx, 0, $lei) }; skip $@, 3 if $@; @@ -158,21 +157,20 @@ for my $zsfx (qw(gz bz2 xz)) { # XXX should we support zst, zz, lzo, lzma? ok($dc_cmd, "decompressor for .$zsfx"); my $f = "$fn.$zsfx"; my $wcb = $wcb_get->($mbox, $f); - $wcb->(\(my $dup = $buf), $deadbeef); + $wcb->(\(my $dup = $buf), { %$deadbeef }); $commit->($wcb); my $uncompressed = xqx([@$dc_cmd, $f]); is($uncompressed, $orig, "$zsfx works unlocked"); - local $lei->{opt} = { jobs => 2 }; # for atomic writes unlink $f or BAIL_OUT "unlink $!"; $wcb = $wcb_get->($mbox, $f); - $wcb->(\($dup = $buf), $deadbeef); + $wcb->(\($dup = $buf), { %$deadbeef }); $commit->($wcb); is(xqx([@$dc_cmd, $f]), $orig, "$zsfx matches with lock"); local $lei->{opt} = { augment => 1 }; $wcb = $wcb_get->($mbox, $f); - $wcb->(\($dup = $buf . "\nx\n"), $deadbeef); + $wcb->(\($dup = $buf . "\nx\n"), { %$deadbeef }); $commit->($wcb); my $cat = popen_rd([@$dc_cmd, $f]); @@ -182,9 +180,9 @@ for my $zsfx (qw(gz bz2 xz)) { # XXX should we support zst, zz, lzo, lzma? like($raw[1], qr/\nblah\n\nx\n\z/s, "augmented $zsfx"); like($raw[0], qr/\nblah\n\z/s, "original preserved $zsfx"); - local $lei->{opt} = { augment => 1, jobs => 2 }; + local $lei->{opt} = { augment => 1 }; $wcb = $wcb_get->($mbox, $f); - $wcb->(\($dup = $buf . "\ny\n"), $deadbeef); + $wcb->(\($dup = $buf . "\ny\n"), { %$deadbeef }); $commit->($wcb); my @raw3; @@ -242,17 +240,18 @@ 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'); } { # Maildir support - my $each_file = PublicInbox::MdirReader->can('maildir_each_file'); + my $mdr = PublicInbox::MdirReader->new; my $md = "$tmpdir/maildir/"; my $wcb = $wcb_get->('maildir', $md); is(ref($wcb), 'CODE', 'got Maildir callback'); @@ -260,7 +259,7 @@ SKIP: { # FIFO support $wcb->(\(my $x = $buf), $b4dc0ffee); my @f; - $each_file->($md, sub { push @f, shift }); + $mdr->maildir_each_file($md, sub { push @f, shift }); open my $fh, $f[0] or BAIL_OUT $!; is(do { local $/; <$fh> }, $buf, 'wrote to Maildir'); @@ -269,7 +268,7 @@ SKIP: { # FIFO support $wcb->(\($x = $buf."\nx\n"), $deadcafe); my @x = (); - $each_file->($md, sub { push @x, shift }); + $mdr->maildir_each_file($md, sub { push @x, shift }); is(scalar(@x), 1, 'wrote one new file'); ok(!-f $f[0], 'old file clobbered'); open $fh, $x[0] or BAIL_OUT $!; @@ -280,7 +279,7 @@ SKIP: { # FIFO support $wcb->(\($x = $buf."\ny\n"), $deadcafe); $wcb->(\($x = $buf."\ny\n"), $b4dc0ffee); # skipped by dedupe @f = (); - $each_file->($md, sub { push @f, shift }); + $mdr->maildir_each_file($md, sub { push @f, shift }); is(scalar grep(/\A\Q$x[0]\E\z/, @f), 1, 'old file still there'); my @new = grep(!/\A\Q$x[0]\E\z/, @f); is(scalar @new, 1, '1 new file written (b4dc0ffee skipped)');