X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Flei-q-save.t;h=d09c839798325d8eb2c7576e00a59adc0bfc0485;hb=20ab293a131f0ec228932bf3448d1b09e280672b;hp=5940018cd6f95acbc3239bfe7c8f6e1f6a672b0e;hpb=21fd0da3bcfba4d3564d262f88d3fd7479b6d5ee;p=public-inbox.git
diff --git a/t/lei-q-save.t b/t/lei-q-save.t
index 5940018c..d09c8397 100644
--- a/t/lei-q-save.t
+++ b/t/lei-q-save.t
@@ -1,9 +1,10 @@
#!perl -w
-# Copyright (C) 2021 all contributors
+# Copyright (C) all contributors
# License: AGPL-3.0+
use strict; use v5.10.1; use PublicInbox::TestCommon;
use PublicInbox::Smsg;
use List::Util qw(sum);
+use File::Path qw(remove_tree);
my $doc1 = eml_load('t/plack-qp.eml');
$doc1->header_set('Date', PublicInbox::Smsg::date({ds => time - (86400 * 5)}));
@@ -11,7 +12,7 @@ my $doc2 = eml_load('t/utf8.eml');
$doc2->header_set('Date', PublicInbox::Smsg::date({ds => time - (86400 * 4)}));
my $doc3 = eml_load('t/msg_iter-order.eml');
$doc3->header_set('Date', PublicInbox::Smsg::date({ds => time - (86400 * 4)}));
-
+my $cat_env = { VISUAL => 'cat', EDITOR => 'cat' };
my $pre_existing = <<'EOF';
From x Mon Sep 17 00:00:00 2001
Message-ID:
@@ -173,6 +174,7 @@ test_lei(sub {
symlink($o, "$home/ln -s") or
skip "symlinks not supported in $home?: $!", 1;
lei_ok('up', "$home/ln -s");
+ lei_ok('forget-search', "$home/ln -s");
};
my $v2 = "$home/v2"; # v2: as an output destination
@@ -181,7 +183,12 @@ test_lei(sub {
lei_ok(qw(q z:0.. -o), "v2:$v2");
like($lei_err, qr/^# ([1-9][0-9]*) written to \Q$v2\E/sm,
'non-zero write output to stderr');
- lei_ok(qw(q z:0.. -o), "mboxrd:$home/before", '--only', $v2, '-j1,1');
+ lei_ok('-C', $v2, qw(q z:0.. -o), "mboxrd:$home/before",
+ '--only', '.', '-j1,1');
+ lei_ok(['edit-search', "$home/before"], $cat_env);
+ like($lei_out, qr/^\tonly = \Q$v2\E$/sm,
+ 'relative --only saved to absolute path');
+
open my $fh, '<', "$home/before";
PublicInbox::MboxReader->mboxrd($fh, sub { push @before, $_[0] });
isnt(scalar(@before), 0, 'initial v2 written');
@@ -205,7 +212,7 @@ test_lei(sub {
ok($shared < $orig, 'fewer bytes stored with --shared') or
diag "shared=$shared orig=$orig";
- lei_ok([qw(edit-search), $v2s], { VISUAL => 'cat', EDITOR => 'cat' });
+ lei_ok([qw(edit-search), $v2s], $cat_env);
like($lei_out, qr/^\[lei/sm, 'edit-search can cat');
lei_ok('-C', "$home/v2s", qw(q -q -o ../s m:testmessage@example.com));
@@ -232,5 +239,52 @@ test_lei(sub {
and xbail "-ipe $lss[0]: $?";
lei_ok qw(ls-search);
is($lei_err, '', 'no errors w/ fixed config');
+
+ like($lei_out, qr!\Q$home/after\E!, "`after' in ls-search");
+ remove_tree("$home/after");
+ lei_ok qw(forget-search --prune);
+ lei_ok qw(ls-search);
+ unlike($lei_out, qr!\Q$home/after\E!, "`after' pruned");
+
+ my $d = "$home/d";
+ lei_ok [qw(import -q -F eml)], undef,
+ {0 => \"Subject: do not call\n\n"};
+ lei_ok qw(q -o), $d, 's:do not call';
+
+ my @orig = glob("$d/*/*");
+ is(scalar(@orig), 1, 'got one message via argv');
+ lei_ok [qw(import -q -Feml)], undef,
+ {0 => \"Subject: do not ever call\n\n"};
+ lei_ok 'up', $d;
+ is_deeply([glob("$d/*/*")], \@orig, 'nothing written');
+ lei_ok [qw(import -q -Feml)], undef,
+ {0 => \"Subject: do not call, ever\n\n"};
+ lei_ok 'up', $d;
+ @after = glob("$d/*/*");
+ is(scalar(@after), 2, '2 total, messages, now');
+ is_deeply([glob("$d/cur/*")], \@orig, 'cur untouched');
+ my @new = glob("$d/new/*");
+ is(scalar(@new), 1, "new message written to `new'");
+ is(eml_load($new[0])->header('Subject'), 'do not call, ever',
+ 'up retrieved correct message');
+
+ $d = "$home/d-stdin";
+ lei_ok [ qw(q -q -o), $d ], undef, { 0 => \'s:"do not ever call"' };
+ @orig = glob("$d/*/*");
+ is(scalar(@orig), 1, 'got one message via stdin');
+
+ lei_ok [qw(import -q -Feml)], undef,
+ {0 => \"Subject: do not fall or ever call\n\n"};
+ lei_ok [qw(import -q -Feml)], undef,
+ {0 => \"Subject: do not ever call, again\n\n"};
+ lei_ok 'up', $d;
+ @new = glob("$d/new/*");
+ is(scalar(@new), 1, "new message written to `new'") or do {
+ for (@new) { diag "$_ ".eml_load($_)->header('Subject') }
+ };
+ is_deeply([glob("$d/cur/*")], \@orig, 'cur untouched');
+ is(eml_load($new[0])->header('Subject'), 'do not ever call, again',
+ 'up retrieved correct message');
+
});
done_testing;