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 2/2] t/www_listing: use autodie, reduce useless tests
Date: Sun,  7 Jul 2024 05:57:27 +0000	[thread overview]
Message-ID: <20240707055727.3006843-3-e@80x24.org> (raw)
In-Reply-To: <20240707055727.3006843-1-e@80x24.org>

Noisy error checking is noisy and less useful than autodie
diagnostics in case of failure.  Furthermore, Most of the xsys()
failures would not allow us to continue, so favor xsys_e() in
those places.
---
 t/www_listing.t | 77 +++++++++++++++++++++++++------------------------
 1 file changed, 39 insertions(+), 38 deletions(-)

diff --git a/t/www_listing.t b/t/www_listing.t
index 5bca4570..e0d21161 100644
--- a/t/www_listing.t
+++ b/t/www_listing.t
@@ -9,10 +9,11 @@ require_mods(qw(json URI::Escape Plack::Builder HTTP::Tiny));
 my $curl = require_cmd 'curl';
 require PublicInbox::WwwListing;
 require PublicInbox::ManifestJsGz;
-use PublicInbox::Config;
+require PublicInbox::Git;
+require PublicInbox::Config;
 my $json = PublicInbox::Config::json();
+use autodie qw(open close mkdir);
 
-use_ok 'PublicInbox::Git';
 
 my ($tmpdir, $for_destroy) = tmpdir();
 my $bare = PublicInbox::Git->new("$tmpdir/bare.git");
@@ -20,10 +21,9 @@ PublicInbox::Import::init_bare($bare->{git_dir});
 is($bare->manifest_entry, undef, 'empty repo has no manifest entry');
 {
 	my $fi_data = './t/git.fast-import-data';
-	open my $fh, '<', $fi_data or die "open $fi_data: $!";
+	open my $fh, '<', $fi_data;
 	my $env = { GIT_DIR => $bare->{git_dir} };
-	is(xsys([qw(git fast-import --quiet)], $env, { 0 => $fh }), 0,
-		'fast-import');
+	xsys_e [qw(git fast-import --quiet)], $env, { 0 => $fh };
 }
 
 like($bare->manifest_entry->{fingerprint}, qr/\A[a-f0-9]{40}\z/,
@@ -86,26 +86,24 @@ SKIP: {
 	my $sock = tcp_server();
 	my ($host, $port) = tcp_host_port($sock);
 	my @clone = qw(git clone -q -s --bare);
-	is(xsys(@clone, $bare->{git_dir}, $alt), 0, 'clone shared repo');
+	xsys_e @clone, $bare->{git_dir}, $alt;
 
 	PublicInbox::Import::init_bare("$v2/all.git");
 	for my $i (0..2) {
-		is(xsys(@clone, $alt, "$v2/git/$i.git"), 0, "clone epoch $i")
+		xsys_e @clone, $alt, "$v2/git/$i.git";
 	}
-	ok(open(my $fh, '>', "$v2/inbox.lock"), 'mock a v2 inbox');
-	open($fh, '>', "$v2/description") or xbail "open $v2/description: $!";
-	print $fh "a v2 inbox\n" or xbail "print $!";
-	close $fh or xbail "write: $v2/description $!";
-
-	open $fh, '>', "$alt/description" or xbail "open $alt/description $!";
-	print $fh "we're \xc4\x80ll clones\n" or xbail "print $!";
-	close $fh or xbail "write: $alt/description $!";
-	is(xsys('git', "--git-dir=$alt", qw(config gitweb.owner),
-		"lorelei \xc4\x80"), 0,
-		'set gitweb user');
-	open $fh, '>', $cfgfile or xbail "open $cfgfile: $!";
-	$fh->autoflush(1);
-	print $fh <<"" or xbail "print $!";
+	open my $fh, '>', "$v2/inbox.lock";
+	open $fh, '>', "$v2/description";
+	print $fh "a v2 inbox\n";
+	close $fh;
+
+	open $fh, '>', "$alt/description";
+	print $fh "we're \xc4\x80ll clones\n";
+	close $fh;
+	xsys_e 'git', "--git-dir=$alt", qw(config gitweb.owner),
+		"lorelei \xc4\x80";
+	open $fh, '>', $cfgfile;
+	print $fh <<"";
 [publicinbox "bare"]
 	inboxdir = $bare->{git_dir}
 	url = http://$host/bare
@@ -119,12 +117,14 @@ SKIP: {
 	url = http://$host/v2
 	address = v2\@example.com
 
+	close $fh;
+
 	my $env = { PI_CONFIG => $cfgfile };
 	my $cmd = [ '-httpd', '-W0', "--stdout=$out", "--stderr=$err" ];
 	my $psgi = "$tmpdir/pfx.psgi";
 	{
-		open my $psgi_fh, '>', $psgi or xbail "open: $!";
-		print $psgi_fh <<'EOM' or xbail "print $!";
+		open my $psgi_fh, '>', $psgi;
+		print $psgi_fh <<'EOM';
 use PublicInbox::WWW;
 use Plack::Builder;
 my $www = PublicInbox::WWW->new;
@@ -133,7 +133,7 @@ builder {
 	mount '/pfx/' => sub { $www->call(@_) }
 }
 EOM
-		close $psgi_fh or xbail "close: $!";
+		close $psgi_fh;
 	}
 
 	# ensure prefixed mount full clones work:
@@ -142,14 +142,14 @@ EOM
 	ok(run_script(['-clone', "http://$host:$port/pfx", "$tmpdir/pfx" ],
 		undef, $opt), 'pfx clone w/pfx') or diag "clone_err=$clone_err";
 
-	open my $mh, '<', "$tmpdir/pfx/manifest.js.gz" or xbail "open: $!";
+	open my $mh, '<', "$tmpdir/pfx/manifest.js.gz";
 	gunzip(\(do { local $/; <$mh> }) => \(my $mjs = ''));
 	my $mf = $json->decode($mjs);
 	is_deeply([sort keys %$mf], [ qw(/alt /bare /v2/git/0.git
 					/v2/git/1.git /v2/git/2.git) ],
 		'manifest saved');
 	for (keys %$mf) { ok(-d "$tmpdir/pfx$_", "pfx/$_ cloned") }
-	open my $desc, '<', "$tmpdir/pfx/v2/description" or xbail "open: $!";
+	open my $desc, '<', "$tmpdir/pfx/v2/description";
 	$desc = <$desc>;
 	is($desc, "a v2 inbox\n", 'v2 description retrieved');
 
@@ -170,7 +170,7 @@ EOM
 
 	undef $td;
 
-	open $mh, '<', "$tmpdir/incl/manifest.js.gz" or xbail "open: $!";
+	open $mh, '<', "$tmpdir/incl/manifest.js.gz";
 	gunzip(\(do { local $/; <$mh> }) => \($mjs = ''));
 	$mf = $json->decode($mjs);
 	is_deeply([keys %$mf], [ '/alt' ], 'excluded keys skipped in manifest');
@@ -197,11 +197,12 @@ EOM
 
 	undef $td;
 
-	print $fh <<"" or xbail "print $!";
+	open $fh, '>>', $cfgfile;
+	print $fh <<"";
 [publicinbox]
 	wwwlisting = all
 
-	close $fh or xbail "close $!";
+	close $fh;
 	$td = start_script($cmd, $env, { 3 => $sock });
 	undef $sock;
 	tiny_test($json, $host, $port, 1);
@@ -217,10 +218,10 @@ EOM
 		skip('grok-pull v2 or later not available', 12);
 	my $grok_loglevel = $ENV{TEST_GROK_LOGLEVEL} // 'info';
 
-	ok(mkdir("$tmpdir/mirror"), 'prepare grok mirror dest');
+	mkdir "$tmpdir/mirror";
 	my $tail = tail_f("$tmpdir/grok.log");
-	open $fh, '>', "$tmpdir/repos.conf" or xbail $!;
-	print $fh <<"" or xbail $!;
+	open $fh, '>', "$tmpdir/repos.conf";
+	print $fh <<"";
 [core]
 toplevel = $tmpdir/mirror
 manifest = $tmpdir/local-manifest.js.gz
@@ -232,7 +233,7 @@ manifest = \${site}/manifest.js.gz
 [pull]
 [fsck]
 
-	close $fh or xbail $!;
+	close $fh;
 	xsys($grok_pull, '-c', "$tmpdir/repos.conf");
 	is($? >> 8, 0, 'grok-pull exit code as expected');
 	for (qw(alt bare v2/git/0.git v2/git/1.git v2/git/2.git)) {
@@ -241,8 +242,8 @@ manifest = \${site}/manifest.js.gz
 
 	# support per-inbox manifests, handy for v2:
 	# /$INBOX/v2/manifest.js.gz
-	open $fh, '>', "$tmpdir/per-inbox.conf" or xbail $!;
-	print $fh <<"" or xbail $!;
+	open $fh, '>', "$tmpdir/per-inbox.conf";
+	print $fh <<"";
 [core]
 toplevel = $tmpdir/per-inbox
 manifest = $tmpdir/per-inbox-manifest.js.gz
@@ -254,8 +255,8 @@ manifest = \${site}/v2/manifest.js.gz
 [pull]
 [fsck]
 
-	close $fh or xbail $!;
-	ok(mkdir("$tmpdir/per-inbox"), 'prepare single-v2-inbox mirror');
+	close $fh;
+	mkdir "$tmpdir/per-inbox";
 	xsys($grok_pull, '-c', "$tmpdir/per-inbox.conf");
 	is($? >> 8, 0, 'grok-pull exit code as expected');
 	for (qw(v2/git/0.git v2/git/1.git v2/git/2.git)) {
@@ -264,7 +265,7 @@ manifest = \${site}/v2/manifest.js.gz
 	$td->kill;
 	$td->join;
 	is($?, 0, 'no error in exited process');
-	open $fh, '<', $err or BAIL_OUT("open $err failed: $!");
+	open $fh, '<', $err;
 	my $eout = do { local $/; <$fh> };
 	unlike($eout, qr/wide/i, 'no Wide character warnings');
 	unlike($eout, qr/uninitialized/i, 'no uninitialized warnings');

      parent reply	other threads:[~2024-07-07  5:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-07  5:57 [PATCH 0/2] www: manifest.js.gz: handle If-Modified-Since Eric Wong
2024-07-07  5:57 ` [PATCH 1/2] www: manifest.js.gz handles If-Modified-Since Eric Wong
2024-07-07  5:57 ` 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=20240707055727.3006843-3-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).