From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/6] t/www_static: modernize test
Date: Mon, 30 Sep 2024 21:30:03 +0000 [thread overview]
Message-ID: <20240930213008.4014512-2-e@80x24.org> (raw)
In-Reply-To: <20240930213008.4014512-1-e@80x24.org>
autodie is standard in Perl v5.10+ and we now have
PublicInbox::IO::write_file to denoise test setup code.
Then we'll favor the non-wantarray calls to tmpdir() and
rely on an overloaded stringification rather than keeping
the $for_destroy object around.
---
t/www_static.t | 36 ++++++++++++++++--------------------
1 file changed, 16 insertions(+), 20 deletions(-)
diff --git a/t/www_static.t b/t/www_static.t
index 83a96a5e..48d120d6 100644
--- a/t/www_static.t
+++ b/t/www_static.t
@@ -1,17 +1,17 @@
-# Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
+#!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 warnings;
-use Test::More;
+use v5.12;
+use autodie;
use PublicInbox::TestCommon;
-my ($tmpdir, $for_destroy) = tmpdir();
-my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape);
+use PublicInbox::IO qw(write_file);
+my $tmpdir = tmpdir();
require_mods qw(psgi);
require IO::Uncompress::Gunzip;
use_ok 'PublicInbox::WwwStatic';
my $app = sub {
- my $ws = PublicInbox::WwwStatic->new(docroot => $tmpdir, @_);
+ my $ws = PublicInbox::WwwStatic->new(docroot => "$tmpdir", @_);
sub { $ws->call(shift) };
};
@@ -19,9 +19,7 @@ test_psgi($app->(), sub {
my $cb = shift;
my $res = $cb->(GET('/'));
is($res->code, 404, '404 on "/" by default');
- open my $fh, '>', "$tmpdir/index.html" or die;
- print $fh 'hi' or die;
- close $fh or die;
+ write_file '>', "$tmpdir/index.html", 'hi';
$res = $cb->(GET('/'));
is($res->code, 200, '200 with index.html');
is($res->content, 'hi', 'default index.html returned');
@@ -41,8 +39,8 @@ test_psgi($app->(autoindex => 1, index => []), sub {
my $ls = $res->content;
like($ls, qr/index\.html/, 'got listing with index.html');
ok(index($ls, $updir) < 0, 'no updir at /');
- mkdir("$tmpdir/dir") or die;
- rename("$tmpdir/index.html", "$tmpdir/dir/index.html") or die;
+ mkdir "$tmpdir/dir";
+ rename "$tmpdir/index.html", "$tmpdir/dir/index.html";
$res = $cb->(GET('/dir/'));
is($res->code, 200, '200 with autoindex for dir/');
@@ -58,8 +56,8 @@ test_psgi($app->(autoindex => 1, index => []), sub {
like($res->header('Location'), qr!://[^/]+/dir/\z!,
'redirected w/ slash');
- rename("$tmpdir/dir/index.html", "$tmpdir/dir/foo") or die;
- link("$tmpdir/dir/foo", "$tmpdir/dir/foo.gz") or die;
+ rename "$tmpdir/dir/index.html", "$tmpdir/dir/foo";
+ link "$tmpdir/dir/foo", "$tmpdir/dir/foo.gz";
$res = $cb->(GET('/dir/'));
unlike($res->content, qr/>foo\.gz</,
'.gz file hidden if mtime matches uncompressed');
@@ -68,15 +66,13 @@ test_psgi($app->(autoindex => 1, index => []), sub {
$res = $cb->(GET('/dir/foo/bar'));
is($res->code, 404, 'using file as dir fails');
- unlink("$tmpdir/dir/foo") or die;
+ unlink "$tmpdir/dir/foo";
$res = $cb->(GET('/dir/'));
like($res->content, qr/>foo\.gz</,
'.gz shown when no uncompressed version exists');
- open my $fh, '>', "$tmpdir/dir/foo" or die;
- print $fh "uncompressed\n" or die;
- close $fh or die;
- utime(0, 0, "$tmpdir/dir/foo") or die;
+ write_file '>', "$tmpdir/dir/foo", "uncompressed\n";
+ utime 0, 0, "$tmpdir/dir/foo";
$res = $cb->(GET('/dir/'));
my $html = $res->content;
like($html, qr/>foo</, 'uncompressed foo shown');
@@ -86,7 +82,7 @@ test_psgi($app->(autoindex => 1, index => []), sub {
is($res->content, "uncompressed\n",
'got uncompressed on mtime mismatch');
- utime(0, 0, "$tmpdir/dir/foo.gz") or die;
+ utime 0, 0, "$tmpdir/dir/foo.gz";
my $get = GET('/dir/foo');
$get->header('Accept-Encoding' => 'gzip');
$res = $cb->($get);
next prev parent reply other threads:[~2024-09-30 21:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-30 21:30 [PATCH 0/6] test updates + coderepo removal workaround Eric Wong
2024-09-30 21:30 ` Eric Wong [this message]
2024-09-30 21:30 ` [PATCH 2/6] t/www_static: test with our -httpd server, too Eric Wong
2024-09-30 21:30 ` [PATCH 3/6] t/www_static: ensure If-Modified-Since handling works Eric Wong
2024-09-30 21:30 ` [PATCH 4/6] www: improve handling of missing coderepos Eric Wong
2024-09-30 21:30 ` [PATCH 5/6] xt/solver: use `psgi' shortcut for require_mods() Eric Wong
2024-09-30 21:30 ` [PATCH 6/6] t/{config,solver_git}: simplify error handling 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=20240930213008.4014512-2-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).