about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/Import.pm9
-rw-r--r--lib/PublicInbox/LEI.pm5
-rw-r--r--lib/PublicInbox/Spawn.pm9
-rw-r--r--lib/PublicInbox/TestCommon.pm25
-rw-r--r--lib/PublicInbox/V2Writable.pm10
5 files changed, 33 insertions, 25 deletions
diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm
index 60cff9c2..6f387b77 100644
--- a/lib/PublicInbox/Import.pm
+++ b/lib/PublicInbox/Import.pm
@@ -9,7 +9,7 @@ package PublicInbox::Import;
 use strict;
 use parent qw(PublicInbox::Lock);
 use v5.10.1;
-use PublicInbox::Spawn qw(spawn popen_rd);
+use PublicInbox::Spawn qw(run_die popen_rd);
 use PublicInbox::MID qw(mids mid2path);
 use PublicInbox::Address;
 use PublicInbox::Smsg;
@@ -442,13 +442,6 @@ sub add {
         $self->{tip} = ":$commit";
 }
 
-sub run_die ($;$$) {
-        my ($cmd, $env, $rdr) = @_;
-        my $pid = spawn($cmd, $env, $rdr);
-        waitpid($pid, 0) == $pid or die join(' ', @$cmd) .' did not finish';
-        $? == 0 or die join(' ', @$cmd) . " failed: $?\n";
-}
-
 my @INIT_FILES = ('HEAD' => undef, # filled in at runtime
                 'description' => <<EOD,
 Unnamed repository; edit this file 'description' to name the repository.
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index bb77198e..1ba9eff3 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -19,7 +19,7 @@ use PublicInbox::Config;
 use PublicInbox::Syscall qw($SFD_NONBLOCK EPOLLIN EPOLLONESHOT);
 use PublicInbox::Sigfd;
 use PublicInbox::DS qw(now);
-use PublicInbox::Spawn qw(spawn);
+use PublicInbox::Spawn qw(spawn run_die);
 use PublicInbox::OnDestroy;
 use Text::Wrap qw(wrap);
 use File::Path qw(mkpath);
@@ -482,8 +482,7 @@ sub lei_config {
         my $cfg = _lei_cfg($self, 1);
         my $cmd = [ qw(git config -f), $cfg->{'-f'}, @argv ];
         my %rdr = map { $_ => $self->{$_} } (0..2);
-        require PublicInbox::Import;
-        PublicInbox::Import::run_die($cmd, $env, \%rdr);
+        run_die($cmd, $env, \%rdr);
 }
 
 sub lei_init {
diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm
index cb16fcf6..5e2495d2 100644
--- a/lib/PublicInbox/Spawn.pm
+++ b/lib/PublicInbox/Spawn.pm
@@ -19,7 +19,7 @@ use strict;
 use parent qw(Exporter);
 use Symbol qw(gensym);
 use PublicInbox::ProcessPipe;
-our @EXPORT_OK = qw/which spawn popen_rd nodatacow_dir/;
+our @EXPORT_OK = qw(which spawn popen_rd run_die nodatacow_dir);
 our @RLIMITS = qw(RLIMIT_CPU RLIMIT_CORE RLIMIT_DATA);
 
 my $vfork_spawn = <<'VFORK_SPAWN';
@@ -306,4 +306,11 @@ sub popen_rd {
         $ret;
 }
 
+sub run_die ($;$$) {
+        my ($cmd, $env, $rdr) = @_;
+        my $pid = spawn($cmd, $env, $rdr);
+        waitpid($pid, 0) == $pid or die "@$cmd did not finish";
+        $? == 0 or die "@$cmd failed: \$?=$?\n";
+}
+
 1;
diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index 338e760c..b833984d 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -10,8 +10,14 @@ use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD :seek);
 use POSIX qw(dup2);
 use IO::Socket::INET;
 our @EXPORT = qw(tmpdir tcp_server tcp_connect require_git require_mods
-        run_script start_script key2sub xsys xqx eml_load tick
+        run_script start_script key2sub xsys xsys_e xqx eml_load tick
         have_xapian_compact);
+BEGIN {
+        require Test::More;
+        *BAIL_OUT = \&Test::More::BAIL_OUT;
+        *plan = \&Test::More::plan;
+        *skip = \&Test::More::skip;
+}
 
 sub eml_load ($) {
         my ($path, $cb) = @_;
@@ -38,7 +44,7 @@ sub tcp_server () {
                 Type => Socket::SOCK_STREAM(),
                 Listen => 1024,
                 Blocking => 0,
-        ) or Test::More::BAIL_OUT("failed to create TCP server: $!");
+        ) or BAIL_OUT "failed to create TCP server: $!";
 }
 
 sub tcp_connect {
@@ -49,7 +55,7 @@ sub tcp_connect {
                 Type => Socket::SOCK_STREAM(),
                 PeerAddr => $addr,
                 %opt,
-        ) or Test::More::BAIL_OUT("failed to connect to $addr: $!");
+        ) or BAIL_OUT "failed to connect to $addr: $!";
         $s->autoflush(1);
         $s;
 }
@@ -64,8 +70,8 @@ sub require_git ($;$) {
         my $cur_int = ($cur_maj << 24) | ($cur_min << 16) | ($cur_sub // 0);
         if ($cur_int < $req_int) {
                 return 0 if $maybe;
-                Test::More::plan(skip_all =>
-                        "git $req+ required, have $cur_maj.$cur_min.$cur_sub");
+                plan skip_all =>
+                        "git $req+ required, have $cur_maj.$cur_min.$cur_sub";
         }
         1;
 }
@@ -113,8 +119,8 @@ sub require_mods {
         }
         return unless @need;
         my $m = join(', ', @need)." missing for $0";
-        Test::More::skip($m, $maybe) if $maybe;
-        Test::More::plan(skip_all => $m)
+        skip($m, $maybe) if $maybe;
+        plan(skip_all => $m)
 }
 
 sub key2script ($) {
@@ -323,6 +329,11 @@ sub xsys {
         $? >> 8
 }
 
+sub xsys_e { # like "/bin/sh -e"
+        xsys(@_) == 0 or
+                BAIL_OUT (ref $_[0] ? "@{$_[0]}" : "@_"). " failed \$?=$?"
+}
+
 # like `backtick` or qx{} op, but uses spawn() for env/rdr + vfork
 sub xqx {
         my ($cmd, $env, $rdr) = @_;
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index edb8ba57..5a8caa08 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -16,7 +16,7 @@ use PublicInbox::ContentHash qw(content_hash content_digest);
 use PublicInbox::InboxWritable;
 use PublicInbox::OverIdx;
 use PublicInbox::Msgmap;
-use PublicInbox::Spawn qw(spawn popen_rd);
+use PublicInbox::Spawn qw(spawn popen_rd run_die);
 use PublicInbox::SearchIdx qw(log2stack crlf_adjust is_ancestor check_size
         is_bad_blob);
 use IO::Handle; # ->autoflush
@@ -745,9 +745,8 @@ sub git_init {
         my ($self, $epoch) = @_;
         my $git_dir = "$self->{ibx}->{inboxdir}/git/$epoch.git";
         PublicInbox::Import::init_bare($git_dir);
-        my @cmd = (qw/git config/, "--file=$git_dir/config",
-                        'include.path', '../../all.git/config');
-        PublicInbox::Import::run_die(\@cmd);
+        run_die([qw(git config), "--file=$git_dir/config",
+                qw(include.path ../../all.git/config)]);
         fill_alternates($self, $epoch);
         $git_dir
 }
@@ -1222,8 +1221,7 @@ sub unindex_todo ($$$) {
         return if $before == $after;
 
         # ensure any blob can not longer be accessed via dumb HTTP
-        PublicInbox::Import::run_die(['git',
-                "--git-dir=$unit->{git}->{git_dir}",
+        run_die(['git', "--git-dir=$unit->{git}->{git_dir}",
                 qw(-c gc.reflogExpire=now gc --prune=all --quiet)]);
 }