about summary refs log tree commit homepage
path: root/t/lei-q-kw.t
diff options
context:
space:
mode:
Diffstat (limited to 't/lei-q-kw.t')
-rw-r--r--t/lei-q-kw.t23
1 files changed, 18 insertions, 5 deletions
diff --git a/t/lei-q-kw.t b/t/lei-q-kw.t
index 4edee72a..63e46037 100644
--- a/t/lei-q-kw.t
+++ b/t/lei-q-kw.t
@@ -1,5 +1,5 @@
 #!perl -w
-# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict; use v5.10.1; use PublicInbox::TestCommon;
 use POSIX qw(mkfifo);
@@ -9,6 +9,8 @@ use IO::Compress::Gzip qw(gzip);
 use PublicInbox::MboxReader;
 use PublicInbox::LeiToMail;
 use PublicInbox::Spawn qw(popen_rd);
+use File::Path qw(make_path);
+use PublicInbox::IO qw(write_file);
 my $exp = {
         '<qp@example.com>' => eml_load('t/plack-qp.eml'),
         '<testmessage@example.com>' => eml_load('t/utf8.eml'),
@@ -42,6 +44,19 @@ lei_ok(qw(q -o), "maildir:$o", qw(m:qp@example.com));
 @fn = glob("$o/cur/*:2,S");
 is(scalar(@fn), 1, "`seen' flag (but not `replied') set on Maildir file");
 
+{
+        $o = "$ENV{HOME}/dst-existing";
+        make_path(map { "$o/$_" } qw(new cur tmp));
+        my $bp = eml_load('t/data/binary.patch');
+        write_file '>', "$o/cur/binary-patch:2,S", $bp->as_string;
+        lei_ok qw(q --no-import-before m:qp@example.com -o), $o;
+        my @g = glob("$o/*/*");
+        is scalar(@g), 1, 'only newly imported message left';
+        is eml_load($g[0])->header_raw('Message-ID'), '<qp@example.com>';
+        lei qw(q m:binary-patch-test@example);
+        is $lei_out, "[null]\n", 'old message not imported';
+}
+
 SKIP: {
         $o = "$ENV{HOME}/fifo";
         mkfifo($o, 0600) or skip("mkfifo not supported: $!", 1);
@@ -51,7 +66,7 @@ SKIP: {
                 '--import-before fails on non-seekable output');
         like($lei_err, qr/not seekable/, 'unseekable noted in error');
         is(do { local $/; <$cat> }, '', 'no output on FIFO');
-        close $cat;
+        $cat->close;
         $cat = popen_rd(['cat', $o]);
         lei_ok(qw(q m:qp@example.com -o), "mboxrd:$o");
         my $buf = do { local $/; <$cat> };
@@ -80,9 +95,7 @@ my $write_file = sub {
         if ($_[0] =~ /\.gz\z/) {
                 gzip(\($_[1]), $_[0]) or BAIL_OUT 'gzip';
         } else {
-                open my $fh, '>', $_[0] or BAIL_OUT $!;
-                print $fh $_[1] or BAIL_OUT $!;
-                close $fh or BAIL_OUT;
+                write_file '>', $_[0], $_[1];
         }
 };