From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 151931F55F for ; Mon, 2 Oct 2023 20:14:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1696277693; bh=q11049AV54i5MQ7Jl2FYnjnfUil72flE2JCA9/scMlw=; h=Date:From:To:Subject:References:In-Reply-To:From; b=hx12KBGpqD9TdMDmCWSe3OQcJW3IxLZfN2vmu89HKuU4pNW7dfcM5D6mojo+Gj3CK zmrZsfNIpu1p1w5swChoap9LKUrXzA9VikEt64hApfrYnYr7cQjpXBkweCPcYwtig1 /yEMMSvMiv7zWoG9nRT4QzNHZIp8cNaQJZpwoNxY= Date: Mon, 2 Oct 2023 20:14:07 +0000 From: Eric Wong To: meta@public-inbox.org Subject: Re: [PATCH] lei: do label/keyword parsing in optparse Message-ID: <20231002201407.M134587@dcvr> References: <20231002150024.2667263-1-e@80x24.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20231002150024.2667263-1-e@80x24.org> List-Id: Eric Wong 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 # License: AGPL-3.0+ -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 },