* [PATCH 14/14] t/cindex+extsearch: use write_file, autodie, etc.
2023-11-02 9:35 7% [PATCH 00/14] IO/IPC-related cleanups Eric Wong
@ 2023-11-02 9:35 4% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2023-11-02 9:35 UTC (permalink / raw)
To: meta
write_file is a new API which makes setting up config files more
pleasant, while autodie and scalarref redirects (in tests) have
been available for a while, now. So do what we can to reduce
the code burden we have.
---
t/cindex.t | 15 ++++-----------
t/extsearch.t | 48 ++++++++++++++----------------------------------
2 files changed, 18 insertions(+), 45 deletions(-)
diff --git a/t/cindex.t b/t/cindex.t
index 2033945e..60711492 100644
--- a/t/cindex.t
+++ b/t/cindex.t
@@ -8,7 +8,7 @@ use List::Util qw(sum);
use autodie qw(close open rename);
require_mods(qw(json Xapian));
use_ok 'PublicInbox::CodeSearchIdx';
-require PublicInbox::Import;
+use PublicInbox::Import;
my ($tmp, $for_destroy) = tmpdir();
my $pwd = getcwd();
my @unused_keys = qw(last_commit has_threadid skip_docdata);
@@ -45,7 +45,6 @@ ok(run_script([qw(-cindex --dangerous -q), "$tmp/wt0"]), 'cindex internal');
# it's possible for git to emit NUL characters in diffs
# (see c4201214cbf10636e2c1ab9131573f735b42c8d4 in linux.git)
my $zp = create_coderepo 'NUL in patch', sub {
- require PublicInbox::Git;
my $src = PublicInbox::IO::try_cat("$pwd/COPYING");
xsys_e([qw(git init -q)]);
@@ -53,17 +52,13 @@ my $zp = create_coderepo 'NUL in patch', sub {
$src =~ s/\b(Limitation of Liability\.)\n\n/$1\n\0\n/s or
xbail "BUG: no `\\n\\n' in $pwd/COPYING";
- open my $fh, '>', 'f';
- print $fh $src or xbail "print: $!";
- close $fh;
+ PublicInbox::IO::write_file '>', 'f', $src;
xsys_e([qw(/bin/sh -c), <<'EOM']);
git add f &&
git commit -q -m 'initial with NUL character'
EOM
$src =~ s/\n\0\n/\n\n/ or xbail "BUG: no `\\n\\0\\n'";
- open $fh, '>', 'f';
- print $fh $src or xbail "print: $!";
- close $fh;
+ PublicInbox::IO::write_file '>', 'f', $src;
xsys_e([qw(/bin/sh -c), <<'EOM']);
git add f &&
git commit -q -m 'remove NUL character' &&
@@ -207,13 +202,11 @@ my $basic = create_inbox 'basic', indexlevel => 'basic', sub {
};
{
my $env = { PI_CONFIG => "$tmp/pi_config" };
- open my $fh, '>', $env->{PI_CONFIG};
- print $fh <<EOM;
+ PublicInbox::IO::write_file '>', $env->{PI_CONFIG}, <<EOM;
[publicinbox "basictest"]
inboxdir = $basic->{inboxdir}
address = basic\@example.com
EOM
- close $fh;
my $cmd = [ qw(-cindex -u --all --associate -d), "$tmp/ext",
'-I', $basic->{inboxdir} ];
$cidx_out = $cidx_err = '';
diff --git a/t/extsearch.t b/t/extsearch.t
index 2995cf95..1a1eb350 100644
--- a/t/extsearch.t
+++ b/t/extsearch.t
@@ -5,9 +5,9 @@ use v5.12;
use PublicInbox::TestCommon;
use PublicInbox::Config;
use PublicInbox::InboxWritable;
-use Fcntl qw(:seek);
require_git(2.6);
require_mods(qw(json DBD::SQLite Xapian));
+use autodie qw(open rename truncate);
require PublicInbox::Search;
use_ok 'PublicInbox::ExtSearch';
use_ok 'PublicInbox::ExtSearchIdx';
@@ -16,12 +16,10 @@ my ($home, $for_destroy) = tmpdir();
local $ENV{HOME} = $home;
mkdir "$home/.public-inbox" or BAIL_OUT $!;
my $cfg_path = "$home/.public-inbox/config";
-open my $fh, '>', $cfg_path or BAIL_OUT $!;
-print $fh <<EOF or BAIL_OUT $!;
+PublicInbox::IO::write_file '>', $cfg_path, <<EOF;
[publicinboxMda]
spamcheck = none
EOF
-close $fh or BAIL_OUT $!;
my $v2addr = 'v2test@example.com';
my $v1addr = 'v1test@example.com';
ok(run_script([qw(-init -Lbasic -V2 v2test --newsgroup v2.example),
@@ -30,24 +28,18 @@ my $env = { ORIGINAL_RECIPIENT => $v2addr };
my $eml = eml_load('t/utf8.eml');
$eml->header_set('List-Id', '<v2.example.com>');
-open($fh, '+>', undef) or BAIL_OUT $!;
-$fh->autoflush(1);
-print $fh $eml->as_string or BAIL_OUT $!;
-seek($fh, 0, SEEK_SET) or BAIL_OUT $!;
-run_script(['-mda', '--no-precheck'], $env, { 0 => $fh }) or BAIL_OUT '-mda';
+my $in = \($eml->as_string);
+run_script(['-mda', '--no-precheck'], $env, { 0 => $in }) or BAIL_OUT '-mda';
ok(run_script([qw(-init -V1 v1test --newsgroup v1.example), "$home/v1test",
'http://example.com/v1test', $v1addr ]), 'v1test init');
$eml->header_set('List-Id', '<v1.example.com>');
-seek($fh, 0, SEEK_SET) or BAIL_OUT $!;
-truncate($fh, 0) or BAIL_OUT $!;
-print $fh $eml->as_string or BAIL_OUT $!;
-seek($fh, 0, SEEK_SET) or BAIL_OUT $!;
+$in = \$eml->as_string;
$env = { ORIGINAL_RECIPIENT => $v1addr };
-run_script(['-mda', '--no-precheck'], $env, { 0 => $fh }) or BAIL_OUT '-mda';
+run_script(['-mda', '--no-precheck'], $env, { 0 => $in }) or BAIL_OUT '-mda';
run_script([qw(-index -Lbasic), "$home/v1test"]) or BAIL_OUT "index $?";
@@ -103,14 +95,11 @@ if ('with boost') {
}
{ # TODO: -extindex should write this to config
- open $fh, '>>', $cfg_path or BAIL_OUT $!;
- print $fh <<EOF or BAIL_OUT $!;
+ PublicInbox::IO::write_file '>>', $cfg_path, <<EOF;
; for ->ALL
[extindex "all"]
topdir = $home/extindex
EOF
- close $fh or BAIL_OUT $!;
-
my $pi_cfg = PublicInbox::Config->new;
$pi_cfg->fill_all;
ok($pi_cfg->ALL, '->ALL');
@@ -202,11 +191,7 @@ if ('inbox edited') {
is_deeply($res, $exp, 'isearch limited results');
$pi_cfg = $res = $exp = undef;
- open my $rmfh, '+>', undef or BAIL_OUT $!;
- $rmfh->autoflush(1);
- print $rmfh $eml2->as_string or BAIL_OUT $!;
- seek($rmfh, 0, SEEK_SET) or BAIL_OUT $!;
- $opt->{0} = $rmfh;
+ $opt->{0} = \($eml2->as_string);
ok(run_script([qw(-learn rm --all)], undef, $opt), '-learn rm');
ok(run_script([qw(-extindex --all), "$home/extindex"], undef, undef),
@@ -245,13 +230,11 @@ if ('inject w/o indexing') {
isnt($tip, $cmt, '0.git v2 updated');
# inject a message w/o updating index
- rename("$home/v1test/public-inbox", "$home/v1test/skip-index") or
- BAIL_OUT $!;
- open(my $eh, '<', 't/iso-2202-jp.eml') or BAIL_OUT $!;
+ rename("$home/v1test/public-inbox", "$home/v1test/skip-index");
+ open(my $eh, '<', 't/iso-2202-jp.eml');
run_script(['-mda', '--no-precheck'], $env, { 0 => $eh}) or
BAIL_OUT '-mda';
- rename("$home/v1test/skip-index", "$home/v1test/public-inbox") or
- BAIL_OUT $!;
+ rename("$home/v1test/skip-index", "$home/v1test/public-inbox");
my ($in, $out, $err);
$in = $out = $err = '';
@@ -500,10 +483,8 @@ SKIP: {
"$home/v2tmp", 'http://example.com/v2tmp', $tmp_addr ])
or xbail '-init';
$env = { ORIGINAL_RECIPIENT => $tmp_addr };
- open $fh, '+>', undef or xbail "open $!";
- $fh->autoflush(1);
my $mid = 'tmpmsg@example.com';
- print $fh <<EOM or xbail "print $!";
+ my $in = \<<EOM;
From: b\@z
To: b\@r
Message-Id: <$mid>
@@ -511,8 +492,7 @@ Subject: tmpmsg
Date: Tue, 19 Jan 2038 03:14:07 +0000
EOM
- seek $fh, 0, SEEK_SET or xbail "seek $!";
- run_script([qw(-mda --no-precheck)], $env, {0 => $fh}) or xbail '-mda';
+ run_script([qw(-mda --no-precheck)], $env, {0 => $in}) or xbail '-mda';
ok(run_script([qw(-extindex --all), "$home/extindex"]), 'update');
my $nr;
{
@@ -525,7 +505,7 @@ EOM
$mset = $es->search->mset('z:0..');
$nr = $mset->size;
}
- truncate($cfg_path, $old_size) or xbail "truncate $!";
+ truncate($cfg_path, $old_size);
my $rdr = { 2 => \(my $err) };
ok(run_script([qw(-extindex --gc), "$home/extindex"], undef, $rdr),
'gc to get rid of removed inbox');
^ permalink raw reply related [relevance 4%]
* [PATCH 00/14] IO/IPC-related cleanups
@ 2023-11-02 9:35 7% Eric Wong
2023-11-02 9:35 4% ` [PATCH 14/14] t/cindex+extsearch: use write_file, autodie, etc Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2023-11-02 9:35 UTC (permalink / raw)
To: meta
8/14 to replace ProcessIO is a major change that I've been
hammering away at for a bit, and many preceding patches to
eliminate ->close calls make it easier to review.
11-12/14 - Error checking for buffered readline is a PITA
(IO::Handle->error was insufficient until Perl 5.34), and I may
switch to sysread eventually to avoid the double-copy overhead
of buffered bulk I/O, anyways. The only place we really benefit
from userspace buffered disk reads is IdxStack, I think...
The new write_file sub in 9/14 seems long overdue.
Eric Wong (14):
xap_helper.pm: use do_fork to Reset and reseed
ds: replace FD map hash table with array
treewide: use ->close method rather than CORE::close
cindex: drop redundant close on regular FH
treewide: use ->close to call ProcessIO->CLOSE
multi_git: use autodie
git_credential: use autodie where appropriate
replace ProcessIO with untied PublicInbox::IO
io: introduce write_file helper sub
spawn: support PerlIO layer in scalar redirects
treewide: check alternates writes with eof + autodie
treewide: use eof and close to detect readline errors
move read_all, try_cat, and poll_in to PublicInbox::IO
t/cindex+extsearch: use write_file, autodie, etc.
MANIFEST | 4 +-
lib/PublicInbox/CodeSearchIdx.pm | 14 +++---
lib/PublicInbox/Config.pm | 2 +-
lib/PublicInbox/DS.pm | 22 ++++-----
lib/PublicInbox/DirIdle.pm | 2 +-
lib/PublicInbox/Gcf2.pm | 4 +-
lib/PublicInbox/Gcf2Client.pm | 7 ++-
lib/PublicInbox/Git.pm | 36 ++++----------
lib/PublicInbox/GitCredential.pm | 16 +++----
lib/PublicInbox/HTTP.pm | 4 +-
lib/PublicInbox/IO.pm | 80 ++++++++++++++++++++++++++++++++
lib/PublicInbox/IdxStack.pm | 2 +-
lib/PublicInbox/Import.pm | 18 ++++---
lib/PublicInbox/Inbox.pm | 2 +-
lib/PublicInbox/InboxWritable.pm | 2 +-
lib/PublicInbox/InputPipe.pm | 1 -
lib/PublicInbox/LEI.pm | 8 ++--
lib/PublicInbox/LeiALE.pm | 6 +--
lib/PublicInbox/LeiBlob.pm | 3 +-
lib/PublicInbox/LeiConfig.pm | 2 +-
lib/PublicInbox/LeiInput.pm | 5 +-
lib/PublicInbox/LeiMailSync.pm | 3 +-
lib/PublicInbox/LeiMirror.pm | 57 +++++++++--------------
lib/PublicInbox/LeiRediff.pm | 11 ++---
lib/PublicInbox/LeiStoreErr.pm | 2 +-
lib/PublicInbox/LeiSucks.pm | 2 +-
lib/PublicInbox/LeiToMail.pm | 34 +++++++-------
lib/PublicInbox/LeiViewText.pm | 2 +-
lib/PublicInbox/LeiXSearch.pm | 8 ++--
lib/PublicInbox/MailDiff.pm | 21 ++++-----
lib/PublicInbox/MboxReader.pm | 4 +-
lib/PublicInbox/MultiGit.pm | 13 +++---
lib/PublicInbox/ProcessIO.pm | 75 ------------------------------
lib/PublicInbox/ProcessIONBF.pm | 25 ----------
lib/PublicInbox/Qspawn.pm | 5 +-
lib/PublicInbox/SearchIdx.pm | 4 +-
lib/PublicInbox/SolverGit.pm | 38 ++++++---------
lib/PublicInbox/Spawn.pm | 42 ++++++++++-------
lib/PublicInbox/TestCommon.pm | 4 +-
lib/PublicInbox/V2Writable.pm | 2 +-
lib/PublicInbox/ViewVCS.pm | 6 +--
lib/PublicInbox/WWW.pm | 2 +-
lib/PublicInbox/XapHelper.pm | 14 ++----
lib/PublicInbox/XapHelperCxx.pm | 3 +-
script/public-inbox-convert | 6 +--
script/public-inbox-edit | 3 +-
script/public-inbox-init | 4 +-
t/cindex.t | 17 ++-----
t/clone-coderepo.t | 10 ++--
t/extsearch.t | 48 ++++++-------------
t/httpd-corner.t | 2 +-
t/init.t | 2 +-
t/io.t | 33 +++++++++++++
t/lei-mirror.t | 10 ++--
t/lei-q-kw.t | 4 +-
t/spawn.t | 36 +++++++-------
xt/check-run.t | 2 +-
xt/git_async_cmp.t | 4 +-
xt/httpd-async-stream.t | 2 +-
59 files changed, 368 insertions(+), 432 deletions(-)
create mode 100644 lib/PublicInbox/IO.pm
delete mode 100644 lib/PublicInbox/ProcessIO.pm
delete mode 100644 lib/PublicInbox/ProcessIONBF.pm
create mode 100644 t/io.t
^ permalink raw reply [relevance 7%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2023-11-02 9:35 7% [PATCH 00/14] IO/IPC-related cleanups Eric Wong
2023-11-02 9:35 4% ` [PATCH 14/14] t/cindex+extsearch: use write_file, autodie, etc Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
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).