-require './t/common.perl';
-require_git(2.6);
-my $this = (split('/', __FILE__))[-1];
-
-foreach my $mod (qw(DBD::SQLite)) {
- eval "require $mod";
- plan skip_all => "$mod missing for $this" if $@;
-}
-
-my $path = 'blib/script';
-my $index = "$path/public-inbox-index";
-my @xcpdb = ("$path/public-inbox-xcpdb", '-q');
-
-my $mime = PublicInbox::MIME->create(
- header => [
- From => 'a@example.com',
- To => 'test@example.com',
- Subject => 'this is a subject',
- Date => 'Fri, 02 Oct 1993 00:00:00 +0000',
- ],
- body => "hello world\n",
-);
-
-sub import_index_incremental {
- my ($v, $level) = @_;
- my $tmpdir = tempdir("pi-$this-tmp-XXXXXX", TMPDIR => 1, CLEANUP => 1);
+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
+To: test@example.com
+Subject: this is a subject
+Date: Fri, 02 Oct 1993 00:00:00 +0000
+
+hello world
+EOF
+
+my $import_index_incremental = sub {
+ my ($v, $level, $mime) = @_;
+ my $err = '';
+ my $this = "pi-$v-$level-indexlevels";
+ my ($tmpdir, $for_destroy) = tmpdir();
+ local $ENV{PI_CONFIG} = "$tmpdir/config";