From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: Re: [PATCH] lei: do label/keyword parsing in optparse
Date: Mon, 2 Oct 2023 20:14:07 +0000 [thread overview]
Message-ID: <20231002201407.M134587@dcvr> (raw)
In-Reply-To: <20231002150024.2667263-1-e@80x24.org>
Eric Wong <e@80x24.org> wrote:
> +++ b/t/lei-import.t
> @@ -126,6 +126,18 @@ $res = json_utf8->decode($lei_out);
> is_deeply($res->[0]->{kw}, [qw(answered seen)], 'keyword added');
> is_deeply($res->[0]->{L}, [qw(boombox inbox)], 'labels preserved');
>
> +# +kw:seen is not a location
> +ok(!lei(qw(import -F eml +kw:seen)), 'import fails w/ only kw arg');
> +like($lei_err, qr/\bLOCATION\.\.\. or --stdin must be set/, 'error message');
That's unreliable because stdin could be pointed to a
regular file or pipe while running tests, so we shouldn't
inherit.
So I think I'll squash the following in and use autodie a bit
more while I'm at it, too.
---
t/lei-import.t | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/t/lei-import.t b/t/lei-import.t
index 30d8b531..8b09d3aa 100644
--- a/t/lei-import.t
+++ b/t/lei-import.t
@@ -1,14 +1,15 @@
#!perl -w
# 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 v5.12; use PublicInbox::TestCommon;
+use autodie qw(open close);
test_lei(sub {
ok(!lei(qw(import -F bogus), 't/plack-qp.eml'), 'fails with bogus format');
like($lei_err, qr/\bis `eml', not --in-format/, 'gave error message');
lei_ok(qw(q s:boolean), \'search miss before import');
unlike($lei_out, qr/boolean/i, 'no results, yet');
-open my $fh, '<', 't/data/0001.patch' or BAIL_OUT $!;
+open my $fh, '<', 't/data/0001.patch';
lei_ok([qw(import -F eml -)], undef, { %$lei_opt, 0 => $fh },
\'import single file from stdin') or diag $lei_err;
close $fh;
@@ -18,7 +19,7 @@ lei_ok(qw(q s:boolean -f mboxrd), \'blob accessible after import');
my $expect = [ eml_load('t/data/0001.patch') ];
require PublicInbox::MboxReader;
my @cmp;
- open my $fh, '<', \$lei_out or BAIL_OUT "open :scalar: $!";
+ open my $fh, '<', \$lei_out;
PublicInbox::MboxReader->mboxrd($fh, sub {
my ($eml) = @_;
$eml->header_set('Status');
@@ -127,8 +128,10 @@ is_deeply($res->[0]->{kw}, [qw(answered seen)], 'keyword added');
is_deeply($res->[0]->{L}, [qw(boombox inbox)], 'labels preserved');
# +kw:seen is not a location
-ok(!lei(qw(import -F eml +kw:seen)), 'import fails w/ only kw arg');
-like($lei_err, qr/\bLOCATION\.\.\. or --stdin must be set/, 'error message');
+open my $null, '<', '/dev/null';
+ok(!lei([qw(import -F eml +kw:seen)], undef, { %$lei_opt, 0 => $null }),
+ 'import fails w/ only kw arg');
+like($lei_err, qr/\bLOCATION\.\.\. or --stdin must be set/s, 'error message');
lei_ok([qw(import -F eml +kw:flagged)], # no lone dash (`-')
undef, { %$lei_opt, 0 => \$eml_str },
prev parent reply other threads:[~2023-10-02 20:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-02 15:00 [PATCH] lei: do label/keyword parsing in optparse Eric Wong
2023-10-02 20:14 ` Eric Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231002201407.M134587@dcvr \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).