user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH] tests: consistently check for xapian-compact
Date: Mon, 14 Sep 2020 06:29:26 +0000	[thread overview]
Message-ID: <20200914062926.13313-1-e@yhbt.net> (raw)

We may need to test against development versions of Xapian,
which may rely on setting `XAPIAN_COMPACT=xapian-compact-1.5'.
Ensure it's possible to do that.

And add a missing check in t/xcpdb-reshard.t, too.
---
 lib/PublicInbox/TestCommon.pm | 9 ++++++++-
 t/convert-compact.t           | 3 +--
 t/indexlevels-mirror.t        | 6 ++----
 t/nntpd.t                     | 2 +-
 t/xcpdb-reshard.t             | 2 +-
 5 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index 42819179..299b9c6a 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) = @_;
@@ -397,6 +398,12 @@ sub start_script {
 	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;
 use strict;
 
diff --git a/t/convert-compact.t b/t/convert-compact.t
index 575262e8..e479476d 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 291e0d2f..b12bd3cb 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 @@ my $import_index_incremental = sub {
 
 	# 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 @@ my $import_index_incremental = sub {
 	   '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 14db1a93..c7a7ee6b 100644
--- a/t/nntpd.t
+++ b/t/nntpd.t
@@ -349,7 +349,7 @@ Date: Fri, 02 Oct 1993 00:00:00 +0000
 	# -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 c1af5d9a..ede736c1 100644
--- a/t/xcpdb-reshard.t
+++ b/t/xcpdb-reshard.t
@@ -45,7 +45,7 @@ my %nums = map {; "$_->{num}" => 1 } @$orig;
 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');

                 reply	other threads:[~2020-09-14  6:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200914062926.13313-1-e@yhbt.net \
    --to=e@yhbt.net \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).