diff options
author | Eric Wong <e@80x24.org> | 2020-12-31 13:51:42 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-01-01 05:00:39 +0000 |
commit | 9c7737d056f832824812086373a13922dd08a0c5 (patch) | |
tree | 5d7e73f0aac58984095c601afb906323179b0241 /lib/PublicInbox/TestCommon.pm | |
parent | 52acde10d4c149bb73b717abdc70720be9a4fe24 (diff) | |
download | public-inbox-9c7737d056f832824812086373a13922dd08a0c5.tar.gz |
It seems like a more logical place for it, but we'll favor the newly-added xsys_e() in tests for BAIL_OUT use.
Diffstat (limited to 'lib/PublicInbox/TestCommon.pm')
-rw-r--r-- | lib/PublicInbox/TestCommon.pm | 25 |
1 files changed, 18 insertions, 7 deletions
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) = @_; |