]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/lei-q-save.t
www: fix manifest.js.gz for default publicInbox.grokManifest
[public-inbox.git] / t / lei-q-save.t
index 753d5b2080b3767f97faff96dbe18f59667a708b..6c5920883a7cbae9481c982a2f611b1772834ca0 100644 (file)
@@ -3,6 +3,8 @@
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict; use v5.10.1; use PublicInbox::TestCommon;
 use PublicInbox::Smsg;
+use List::Util qw(sum);
+
 my $doc1 = eml_load('t/plack-qp.eml');
 $doc1->header_set('Date', PublicInbox::Smsg::date({ds => time - (86400 * 5)}));
 my $doc2 = eml_load('t/utf8.eml');
@@ -25,7 +27,8 @@ test_lei(sub {
        lei_ok [qw(import -q -F eml -)], undef, { 0 => \$in, %$lei_opt };
        lei_ok qw(q -q --save z:0.. d:last.week..), '-o', "MAILDIR:$home/md/";
        my %before = map { $_ => 1 } glob("$home/md/cur/*");
-       is_deeply(eml_load((keys %before)[0]), $doc1, 'doc1 matches');
+       my $f = (keys %before)[0] or xbail({before => \%before});
+       is_deeply(eml_load($f), $doc1, 'doc1 matches');
        lei_ok qw(ls-mail-sync);
        is($lei_out, "maildir:$home/md\n", 'canonicalized mail sync name');
 
@@ -42,10 +45,11 @@ test_lei(sub {
        lei_ok qw(up -q md -C), $home;
        lei_ok qw(up -q . -C), "$home/md";
        lei_ok qw(up -q), "/$home/md";
-       my %after = map { $_ => 1 } glob("$home/md/cur/*");
+       my %after = map { $_ => 1 } glob("$home/md/{new,cur}/*");
        is(delete $after{(keys(%before))[0]}, 1, 'original message kept');
        is(scalar(keys %after), 1, 'one new message added');
-       is_deeply(eml_load((keys %after)[0]), $doc2, 'doc2 matches');
+       $f = (keys %after)[0] or xbail({after => \%after});
+       is_deeply(eml_load($f), $doc2, 'doc2 matches');
 
        # check stdin
        lei_ok [qw(q --save - -o), "mboxcl2:mbcl2" ],
@@ -155,7 +159,7 @@ test_lei(sub {
        $im->add(PublicInbox::Eml->new($diff));
        $im->done;
        lei_ok('up', $o);
-       @m = glob("$o/cur/*");
+       @m = glob("$o/{new,cur}/*");
        is(scalar(@m), 2, 'got 2nd result due to different OID');
 
        SKIP: {
@@ -163,5 +167,36 @@ test_lei(sub {
                        skip "symlinks not supported in $home?: $!", 1;
                lei_ok('up', "$home/ln -s");
        };
+
+       my $v2 = "$home/v2"; # v2: as an output destination
+       my (@before, @after);
+       require PublicInbox::MboxReader;
+       lei_ok(qw(q z:0.. -o), "v2:$v2");
+       lei_ok(qw(q z:0.. -o), "mboxrd:$home/before", '--only', $v2, '-j1,1');
+       open my $fh, '<', "$home/before";
+       PublicInbox::MboxReader->mboxrd($fh, sub { push @before, $_[0] });
+       isnt(scalar(@before), 0, 'initial v2 written');
+       my $orig = sum(map { -f $_ ? -s _ : () } (
+                       glob("$v2/git/0.git/objects/*/*")));
+       lei_ok(qw(import t/data/0001.patch));
+       lei_ok 'up', $v2;
+       lei_ok(qw(q z:0.. -o), "mboxrd:$home/after", '--only', $v2, '-j1,1');
+       open $fh, '<', "$home/after";
+       PublicInbox::MboxReader->mboxrd($fh, sub { push @after, $_[0] });
+
+       my $last = shift @after;
+       $last->header_set('Status');
+       is_deeply($last, eml_load('t/data/0001.patch'), 'lei up worked on v2');
+       is_deeply(\@before, \@after, 'got same results');
+
+       my $v2s = "$home/v2s";
+       lei_ok(qw(q --shared z:0.. -o), "v2:$v2s");
+       my $shared = sum(map { -f $_ ? -s _ : () } (
+                       glob("$v2s/git/0.git/objects/*/*")));
+       ok($shared < $orig, 'fewer bytes stored with --shared') or
+               diag "shared=$shared orig=$orig";
+
+       lei_ok([qw(edit-search), $v2s], { VISUAL => 'cat', EDITOR => 'cat' });
+       like($lei_out, qr/^\[lei/sm, 'edit-search can cat');
 });
 done_testing;