unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 09/21] t/lei_to_mail: modernize and document test
Date: Wed,  4 Oct 2023 03:49:21 +0000	[thread overview]
Message-ID: <20231004034933.3343930-10-e@80x24.org> (raw)
In-Reply-To: <20231004034933.3343930-1-e@80x24.org>

---
 t/lei_to_mail.t | 37 +++++++++++++++++++------------------
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/t/lei_to_mail.t b/t/lei_to_mail.t
index d692751c..dbd33909 100644
--- a/t/lei_to_mail.t
+++ b/t/lei_to_mail.t
@@ -1,9 +1,10 @@
 #!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 Test::More;
+# tests PublicInbox::LeiToMail internals (unstable API)
+# Not as needed now that lei functionality has been ironed out
+use v5.12;
+use autodie qw(open sysopen unlink);
 use PublicInbox::TestCommon;
 use PublicInbox::Eml;
 use Fcntl qw(SEEK_SET O_RDONLY O_NONBLOCK);
@@ -74,7 +75,7 @@ for my $mbox (@MBOX) {
 
 my ($tmpdir, $for_destroy) = tmpdir();
 local $ENV{TMPDIR} = $tmpdir;
-open my $err, '>>', "$tmpdir/lei.err" or BAIL_OUT $!;
+open my $err, '>>', "$tmpdir/lei.err";
 my $lei = bless { 2 => $err, cmd => 'test' }, 'PublicInbox::LEI';
 my $commit = sub {
 	$_[0] = undef; # wcb
@@ -114,16 +115,16 @@ my $orig = do {
 	ok(-f $fn && !-s _, 'empty file created');
 	$wcb->(\(my $dup = $buf), $deadbeef);
 	$commit->($wcb);
-	open my $fh, '<', $fn or BAIL_OUT $!;
+	open my $fh, '<', $fn;
 	my $raw = do { local $/; <$fh> };
 	like($raw, qr/^blah\n/sm, 'wrote content');
-	unlink $fn or BAIL_OUT $!;
+	unlink $fn;
 
 	$wcb = $wcb_get->($mbox, $fn);
 	ok(-f $fn && !-s _, 'truncated mbox destination');
 	$wcb->(\($dup = $buf), $deadbeef);
 	$commit->($wcb);
-	open $fh, '<', $fn or BAIL_OUT $!;
+	open $fh, '<', $fn;
 	is(do { local $/; <$fh> }, $raw, 'wrote identical content');
 	$raw;
 };
@@ -162,7 +163,7 @@ for my $zsfx (qw(gz bz2 xz)) {
 		my $uncompressed = xqx([@$dc_cmd, $f]);
 		is($uncompressed, $orig, "$zsfx works unlocked");
 
-		unlink $f or BAIL_OUT "unlink $!";
+		unlink $f;
 		$wcb = $wcb_get->($mbox, $f);
 		$wcb->(\($dup = $buf), { %$deadbeef });
 		$commit->($wcb);
@@ -201,14 +202,14 @@ my $as_orig = sub {
 	$eml->as_string;
 };
 
-unlink $fn or BAIL_OUT $!;
+unlink $fn;
 if ('default deduplication uses content_hash') {
 	my $wcb = $wcb_get->('mboxo', $fn);
 	$deadbeef->{kw} = [];
 	$wcb->(\(my $x = $buf), $deadbeef) for (1..2);
 	$commit->($wcb);
 	my $cmp = '';
-	open my $fh, '<', $fn or BAIL_OUT $!;
+	open my $fh, '<', $fn;
 	PublicInbox::MboxReader->mboxo($fh, sub { $cmp .= $as_orig->(@_) });
 	is($cmp, $buf, 'only one message written');
 
@@ -216,7 +217,7 @@ if ('default deduplication uses content_hash') {
 	$wcb = $wcb_get->('mboxo', $fn);
 	$wcb->(\($x = $buf . "\nx\n"), $deadbeef) for (1..2);
 	$commit->($wcb);
-	open $fh, '<', $fn or BAIL_OUT $!;
+	open $fh, '<', $fn;
 	my @x;
 	PublicInbox::MboxReader->mboxo($fh, sub { push @x, $as_orig->(@_) });
 	is(scalar(@x), 2, 'augmented mboxo');
@@ -225,12 +226,12 @@ if ('default deduplication uses content_hash') {
 }
 
 { # stdout support
-	open my $tmp, '+>', undef or BAIL_OUT $!;
+	open my $tmp, '+>', undef;
 	local $lei->{1} = $tmp;
 	my $wcb = $wcb_get->('mboxrd', '/dev/stdout');
 	$wcb->(\(my $x = $buf), $deadbeef);
 	$commit->($wcb);
-	seek($tmp, 0, SEEK_SET) or BAIL_OUT $!;
+	seek($tmp, 0, SEEK_SET);
 	my $cmp = '';
 	PublicInbox::MboxReader->mboxrd($tmp, sub { $cmp .= $as_orig->(@_) });
 	is($cmp, $buf, 'message written to stdout');
@@ -240,7 +241,7 @@ SKIP: { # FIFO support
 	use POSIX qw(mkfifo);
 	my $fn = "$tmpdir/fifo";
 	mkfifo($fn, 0600) or skip("mkfifo not supported: $!", 1);
-	sysopen(my $cat, $fn, O_RDONLY|O_NONBLOCK) or BAIL_OUT $!;
+	sysopen(my $cat, $fn, O_RDONLY|O_NONBLOCK);
 	my $wcb = $wcb_get->('mboxo', $fn);
 	$wcb->(\(my $x = $buf), $deadbeef);
 	$commit->($wcb);
@@ -260,7 +261,7 @@ SKIP: { # FIFO support
 
 	my @f;
 	$mdr->maildir_each_file($md, sub { push @f, shift });
-	open my $fh, '<', $f[0] or BAIL_OUT $!;
+	open my $fh, '<', $f[0];
 	is(do { local $/; <$fh> }, $buf, 'wrote to Maildir');
 
 	$wcb = $wcb_get->('maildir', $md);
@@ -271,7 +272,7 @@ SKIP: { # FIFO support
 	$mdr->maildir_each_file($md, sub { push @x, shift });
 	is(scalar(@x), 1, 'wrote one new file');
 	ok(!-f $f[0], 'old file clobbered');
-	open $fh, '<', $x[0] or BAIL_OUT $!;
+	open $fh, '<', $x[0];
 	is(do { local $/; <$fh> }, $buf."\nx\n", 'wrote new file to Maildir');
 
 	local $lei->{opt}->{augment} = 1;
@@ -283,9 +284,9 @@ SKIP: { # FIFO support
 	is(scalar grep(/\A\Q$x[0]\E\z/, @f), 1, 'old file still there');
 	my @new = grep(!/\A\Q$x[0]\E\z/, @f);
 	is(scalar @new, 1, '1 new file written (b4dc0ffee skipped)');
-	open $fh, '<', $x[0] or BAIL_OUT $!;
+	open $fh, '<', $x[0];
 	is(do { local $/; <$fh> }, $buf."\nx\n", 'old file untouched');
-	open $fh, '<', $new[0] or BAIL_OUT $!;
+	open $fh, '<', $new[0];
 	is(do { local $/; <$fh> }, $buf."\ny\n", 'new file written');
 }
 

  parent reply	other threads:[~2023-10-04  3:49 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-04  3:49 [PATCH 00/21] lei + IPC related stuff Eric Wong
2023-10-04  3:49 ` [PATCH 01/21] lei: drop stores explicitly at daemon shutdown Eric Wong
2023-10-04  3:49 ` [PATCH 02/21] ds: hoist out close_non_busy Eric Wong
2023-10-04  3:49 ` [PATCH 03/21] ds: don't pass FD map to post_loop_do callback Eric Wong
2023-10-04  3:49 ` [PATCH 04/21] move all non-test @post_loop_do into named subs Eric Wong
2023-10-04  3:49 ` [PATCH 05/21] lei: close DirIdle (inotify) early at daemon shutdown Eric Wong
2023-10-04  3:49 ` [PATCH 06/21] input_pipe: {args} is never undefined Eric Wong
2023-10-04  3:49 ` [PATCH 07/21] lei: do_env combines fchdir and local Eric Wong
2023-10-04  3:49 ` [PATCH 08/21] lei: get rid of l2m_progress PktOp callback Eric Wong
2023-10-04  3:49 ` Eric Wong [this message]
2023-10-04  3:49 ` [PATCH 10/21] lei: reuse PublicInbox::Config::noop Eric Wong
2023-10-04  3:49 ` [PATCH 11/21] lei: keep signals blocked on daemon shutdown Eric Wong
2023-10-04  3:49 ` [PATCH 12/21] mbox_lock: retry on EINTR and use autodie Eric Wong
2023-10-04  3:49 ` [PATCH 13/21] lock: retry on EINTR, improve error reporting Eric Wong
2023-10-04  3:49 ` [PATCH 14/21] treewide: use PublicInbox::Lock->new Eric Wong
2023-10-04  3:49 ` [PATCH 15/21] gcf2: use PublicInbox::Lock Eric Wong
2023-10-04  3:49 ` [PATCH 16/21] spawn: use autodie and PublicInbox::Lock Eric Wong
2023-10-04  3:49 ` [PATCH 17/21] xap_helper: retry flock on EINTR Eric Wong
2023-10-04  3:49 ` [PATCH 18/21] xap_helper.pm: use EINTR-aware recv_cmd Eric Wong
2023-10-04  3:49 ` [PATCH 19/21] spawn: drop checks for directory writability Eric Wong
2023-10-04  3:49 ` [PATCH 20/21] lei: document and local-ize $OPT hashref Eric Wong
2023-10-04  3:49 ` [PATCH 21/21] searchidx: fix redundant `in' in warning message Eric Wong

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=20231004034933.3343930-10-e@80x24.org \
    --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).