X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FTestCommon.pm;h=b833984d95d966172ceebd6ae258f2bd90e7c2ce;hb=9c7737d056f832824812086373a13922dd08a0c5;hp=338e760c5be8ec24d084804a3be9771616b645d3;hpb=52acde10d4c149bb73b717abdc70720be9a4fe24;p=public-inbox.git 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) = @_;