lib/PublicInbox/TestCommon.pm | 9 ++++++++- t/convert-compact.t | 3 +-- t/indexlevels-mirror.t | 6 ++---- t/nntpd.t | 2 +- t/xcpdb-reshard.t | 2 +- diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm index 428191791b5ff35788dc365804d477eeec6a58a9..299b9c6a830833966df288687270d27ae95e1b49 100644 --- a/lib/PublicInbox/TestCommon.pm +++ b/lib/PublicInbox/TestCommon.pm @@ -10,7 +10,8 @@ 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 xqx eml_load tick + have_xapian_compact); sub eml_load ($) { my ($path, $cb) = @_; @@ -395,6 +396,12 @@ die "FAIL: ",join(' ', $key, @argv), ": $!\n"; } } PublicInboxTestProcess->new($pid, $tail_pid); +} + +sub have_xapian_compact () { + require PublicInbox::Spawn; + # $ENV{XAPIAN_COMPACT} is used by PublicInbox/Xapcmd.pm, too + PublicInbox::Spawn::which($ENV{XAPIAN_COMPACT} || 'xapian-compact'); } package PublicInboxTestProcess; diff --git a/t/convert-compact.t b/t/convert-compact.t index 575262e8e5d3360b85825d686c39ba3835ae6e34..e479476d8589aac7be5a6f024febf31df9002682 100644 --- a/t/convert-compact.t +++ b/t/convert-compact.t @@ -4,11 +4,10 @@ use strict; use warnings; use Test::More; use PublicInbox::Eml; -use PublicInbox::Spawn qw(which); use PublicInbox::TestCommon; require_git(2.6); require_mods(qw(DBD::SQLite Search::Xapian)); -which('xapian-compact') or +have_xapian_compact or plan skip_all => 'xapian-compact missing for '.__FILE__; use_ok 'PublicInbox::V2Writable'; diff --git a/t/indexlevels-mirror.t b/t/indexlevels-mirror.t index 291e0d2fc121c8f5dc2d3440580d13ca19aea86e..b12bd3cb2b177276cb01397ad660cf10dc9f571e 100644 --- a/t/indexlevels-mirror.t +++ b/t/indexlevels-mirror.t @@ -6,13 +6,11 @@ use Test::More; use PublicInbox::Eml; use PublicInbox::Inbox; use PublicInbox::InboxWritable; -use PublicInbox::Spawn qw(which); require PublicInbox::Admin; use PublicInbox::TestCommon; my $PI_TEST_VERSION = $ENV{PI_TEST_VERSION} || 2; require_git('2.6') if $PI_TEST_VERSION == 2; require_mods(qw(DBD::SQLite)); -my $have_xapian_compact = which($ENV{XAPIAN_COMPACT} || 'xapian-compact'); my $mime = PublicInbox::Eml->new(<<'EOF'); From: a@example.com @@ -43,7 +41,7 @@ $im->done; # index master (required for v1) my @cmd = (qw(-index -j0), $ibx->{inboxdir}, "-L$level"); - push @cmd, '-c' if $have_xapian_compact; + push @cmd, '-c' if have_xapian_compact; ok(run_script(\@cmd, undef, { 2 => \$err }), 'index master'); my $ro_master = PublicInbox::Inbox->new({ inboxdir => $ibx->{inboxdir}, @@ -164,7 +162,7 @@ is(PublicInbox::Admin::detect_indexlevel($ro_mirror), $level, 'indexlevel detectable by Admin '.$v.$level); SKIP: { - skip 'xapian-compact missing', 1 if !$have_xapian_compact; + skip 'xapian-compact missing', 1 if have_xapian_compact; my $cmd = [ qw(-compact), $mirror ]; ok(run_script($cmd, undef, { 2 => \$err}), "compact $level"); } diff --git a/t/nntpd.t b/t/nntpd.t index 14db1a93019771426635cecc8fafedd9d2c7c920..c7a7ee6bb3ad512a1ed0b12807ae93016a58be7d 100644 --- a/t/nntpd.t +++ b/t/nntpd.t @@ -349,7 +349,7 @@ } # -compact requires Xapian SKIP: { require_mods('Search::Xapian', 2); - which('xapian-compact') or skip 'xapian-compact missing', 2; + have_xapian_compact or skip 'xapian-compact missing', 2; is(xsys(qw(git config), "--file=$home/.public-inbox/config", "publicinbox.$group.indexlevel", 'medium'), 0, 'upgraded indexlevel'); diff --git a/t/xcpdb-reshard.t b/t/xcpdb-reshard.t index c1af5d9a8f669ac53f25d00e925a9e928b651750..ede736c1524b5597cf0c151aa1b57b70c4ebd9a0 100644 --- a/t/xcpdb-reshard.t +++ b/t/xcpdb-reshard.t @@ -45,7 +45,7 @@ # ensure we can go up or down in shards, or stay the same: for my $R (qw(2 4 1 3 3)) { delete $ibx->{search}; # release old handles my $cmd = [@xcpdb, "-R$R", $ibx->{inboxdir}]; - push @$cmd, '--compact' if $R == 1; + push @$cmd, '--compact' if $R == 1 && have_xapian_compact; ok(run_script($cmd), "xcpdb -R$R"); my @new_shards = grep(m!/\d+\z!, glob("$ibx->{inboxdir}/xap*/*")); is(scalar(@new_shards), $R, 'resharded to two shards');