From 3863b32ecbfb8af20b6650bd134a251a6b290ec7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 15 Jan 2021 23:36:23 -1200 Subject: lei: q: results output to Maildir and mbox* working All the augment and deduplication stuff seems to be working based on unit tests. OpPipe is a nice general addition that will probably make future state machines easier. --- t/lei.t | 20 ++++++++++++++++++++ t/lei_to_mail.t | 4 +++- 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 't') diff --git a/t/lei.t b/t/lei.t index 2349dca4..c4692217 100644 --- a/t/lei.t +++ b/t/lei.t @@ -7,6 +7,7 @@ use Test::More; use PublicInbox::TestCommon; use PublicInbox::Config; use File::Path qw(rmtree); +use Fcntl qw(SEEK_SET); require_git 2.6; require_mods(qw(json DBD::SQLite Search::Xapian)); my $opt = { 1 => \(my $out = ''), 2 => \(my $err = '') }; @@ -188,6 +189,25 @@ my $test_external = sub { # No double-quoting should be imposed on users on the CLI $lei->('q', 's:use boolean prefix'); like($out, qr/search: use boolean prefix/, 'phrase search got result'); + + $lei->('q', '-o', "mboxcl2:$home/mbox", 's:use boolean prefix'); + open my $mb, '<', "$home/mbox" or fail "no mbox: $!"; + my @s = grep(/^Subject:/, <$mb>); + is(scalar(@s), 1, '1 result in mbox'); + $lei->('q', '-a', '-o', "mboxcl2:$home/mbox", 's:see attachment'); + is($err, '', 'no errors from augment'); + seek($mb, 0, SEEK_SET) or BAIL_OUT "seek: $!"; + @s = grep(/^Subject:/, <$mb>); + is(scalar(@s), 2, '2 results in mbox'); + + $lei->('q', '-a', '-o', "mboxcl2:$home/mbox", 's:nonexistent'); + is($err, '', 'no errors on no results'); + seek($mb, 0, SEEK_SET) or BAIL_OUT "seek: $!"; + my @s2 = grep(/^Subject:/, <$mb>); + is_deeply(\@s2, \@s, 'same 2 old results w/ --augment and bad search'); + + $lei->('q', '-o', "mboxcl2:$home/mbox", 's:nonexistent'); + is(-s "$home/mbox", 0, 'clobber w/o --augment'); }; my $test_lei_common = sub { diff --git a/t/lei_to_mail.t b/t/lei_to_mail.t index d5beb3d2..083e0df4 100644 --- a/t/lei_to_mail.t +++ b/t/lei_to_mail.t @@ -94,7 +94,9 @@ my $wcb_get = sub { my $dup = Storable::thaw(Storable::freeze($l2m)); is_deeply($dup, $l2m, "$fmt round-trips through storable"); } - $l2m->do_prepare($lei); + $l2m->pre_augment($lei); + $l2m->do_augment($lei); + $l2m->post_augment($lei); my $cb = $l2m->write_cb($lei); delete $lei->{1}; $cb; -- cgit v1.2.3-24-ge0c7