about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-03-04 18:38:29 -0700
committerEric Wong <e@80x24.org>2021-03-05 07:20:21 +0000
commit7d186c6fa885c7b04c9e2a65b3fc501120b7866f (patch)
treefad4e8c5a14b038246ae68fa058e6b068714eb62 /t
parent2958cd17d58c79c952afae6cfd594595ffcaf4fa (diff)
downloadpublic-inbox-7d186c6fa885c7b04c9e2a65b3fc501120b7866f.tar.gz
commit 6c551bffd75afb41d9b5e4774068abe7e06ed0e7
("lei q: --import-augment for mbox and mbox.gz") added a check to
in _pre_augment_mbox for the option being a ref() to distinguish
between default values and user-supplied values (which are
non-ref SCALARs from Getopt::Long).

However, LeiQuery failed to use a SCALAR ref as the default
value, making the check in _pre_augment_mbox useless.  We
now update LeiQuery to use \1 instead of 1 as the default
value so "lei q -f mboxrd ..." to stdout works once again.

Unfortunately, testing with redirects pointed to regular
files didn't trigger the code paths being updated.  Testing
with a FIFO revealed further bugs in the FIFO handling code
which are also fixed in this commit.

We'll also update the $lei->out error message to be
less-specific about "stdout" and use the term "output", instead,
since LeiToMail replaces stdout for all mbox outputs.
Diffstat (limited to 't')
-rw-r--r--t/lei-q-kw.t25
1 files changed, 19 insertions, 6 deletions
diff --git a/t/lei-q-kw.t b/t/lei-q-kw.t
index 9daeb5b1..917a2c53 100644
--- a/t/lei-q-kw.t
+++ b/t/lei-q-kw.t
@@ -7,7 +7,15 @@ use Fcntl qw(SEEK_SET O_RDONLY O_NONBLOCK);
 use IO::Uncompress::Gunzip qw(gunzip);
 use IO::Compress::Gzip qw(gzip);
 use PublicInbox::MboxReader;
+use PublicInbox::LeiToMail;
 use PublicInbox::Spawn qw(popen_rd);
+my $exp = {
+        '<qp@example.com>' => eml_load('t/plack-qp.eml'),
+        '<testmessage@example.com>' => eml_load('t/utf8.eml'),
+};
+$exp->{'<qp@example.com>'}->header_set('Status', 'OR');
+$exp->{'<testmessage@example.com>'}->header_set('Status', 'O');
+
 test_lei(sub {
 lei_ok(qw(import -F eml t/plack-qp.eml));
 my $o = "$ENV{HOME}/dst";
@@ -42,6 +50,17 @@ SKIP: {
         ok(!lei(qw(q --import-before bogus -o), "mboxrd:$o"),
                 '--import-before fails on non-seekable output');
         is(do { local $/; <$cat> }, '', 'no output on FIFO');
+        close $cat;
+        $cat = popen_rd(['cat', $o]);
+        lei_ok(qw(q m:qp@example.com -o), "mboxrd:$o");
+        my $buf = do { local $/; <$cat> };
+        open my $fh, '<', \$buf or BAIL_OUT $!;
+        PublicInbox::MboxReader->mboxrd($fh, sub {
+                my ($eml) = @_;
+                $eml->header_set('Status', 'OR');
+                is_deeply($eml, $exp->{'<qp@example.com>'},
+                        'FIFO output works as expected');
+        });
 };
 
 lei_ok qw(import -F eml t/utf8.eml), \'for augment test';
@@ -66,12 +85,6 @@ my $write_file = sub {
         }
 };
 
-my $exp = {
-        '<qp@example.com>' => eml_load('t/plack-qp.eml'),
-        '<testmessage@example.com>' => eml_load('t/utf8.eml'),
-};
-$exp->{'<qp@example.com>'}->header_set('Status', 'OR');
-$exp->{'<testmessage@example.com>'}->header_set('Status', 'O');
 for my $sfx ('', '.gz') {
         $o = "$ENV{HOME}/dst.mboxrd$sfx";
         lei_ok(qw(q -o), "mboxrd:$o", qw(m:qp@example.com));