X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FTestCommon.pm;h=5cce44e42bc1fd23a8ce7dea513628abdfc09f68;hb=cfc2f64069e245a700b60113705be477857c51e5;hp=2b78731b8e54ec877c9fdc9631afaf823b94a95e;hpb=4113bc92d0c4aacc4f95676de74bed63a5687bdf;p=public-inbox.git diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm index 2b78731b..5cce44e4 100644 --- a/lib/PublicInbox/TestCommon.pm +++ b/lib/PublicInbox/TestCommon.pm @@ -13,7 +13,7 @@ our @EXPORT; BEGIN { @EXPORT = qw(tmpdir tcp_server tcp_connect require_git require_mods run_script start_script key2sub xsys xsys_e xqx eml_load tick - have_xapian_compact json_utf8 + have_xapian_compact json_utf8 setup_public_inboxes test_lei $lei $lei_out $lei_err $lei_opt); require Test::More; my @methods = grep(!/\W/, @Test::More::EXPORT); @@ -456,13 +456,16 @@ SKIP: { require PublicInbox::Spawn; state $lei_daemon = PublicInbox::Spawn->can('send_cmd4') || eval { require Socket::MsgHdr; 1 }; - $lei_opt = { 1 => \$lei_out, 2 => \$lei_err }; - my $daemon_pid; - my ($tmpdir, $for_destroy) = tmpdir(); - SKIP: { - skip <<'EOM', 1 unless $lei_daemon; + # XXX fix and move this inside daemon-only before 1.7 release + skip <<'EOM', 1 unless $lei_daemon; Socket::MsgHdr missing or Inline::C is unconfigured/missing EOM + $lei_opt = { 1 => \$lei_out, 2 => \$lei_err }; + my ($daemon_pid, $for_destroy); + my $tmpdir = $test_opt->{tmpdir}; + ($tmpdir, $for_destroy) = tmpdir unless $tmpdir; + SKIP: { + skip 'TEST_LEI_ONESHOT set', 1 if $ENV{TEST_LEI_ONESHOT}; my $home = "$tmpdir/lei-daemon"; mkdir($home, 0700) or BAIL_OUT "mkdir: $!"; local $ENV{HOME} = $home; @@ -498,7 +501,53 @@ EOM ok(!kill(0, $daemon_pid), "$t daemon stopped after oneshot"); } }; # SKIP if missing git 2.6+ || Xapian || SQLite || json -} +} # /test_lei + +# returns the pathname to a ~/.public-inbox/config in scalar context, +# ($test_home, $pi_config_pathname) in list context +sub setup_public_inboxes () { + my $test_home = "t/home1"; + my $pi_config = "$test_home/.public-inbox/config"; + my $stamp = "$test_home/setup-stamp"; + my @ret = ($test_home, $pi_config); + return @ret if -f $stamp; + + require PublicInbox::Lock; + my $lk = bless { lock_path => "$test_home/setup.lock" }, + 'PublicInbox::Lock'; + my $end = $lk->lock_for_scope; + return @ret if -f $stamp; + + require PublicInbox::InboxWritable; + local $ENV{PI_CONFIG} = $pi_config; + for my $V (1, 2) { + run_script([qw(-init), "-V$V", "t$V", + '--newsgroup', "t.$V", + "$test_home/t$V", "http://example.com/t$V", + "t$V\@example.com" ]) or BAIL_OUT "init v$V"; + } + my $cfg = PublicInbox::Config->new; + my $seen = 0; + $cfg->each_inbox(sub { + my ($ibx) = @_; + my $im = PublicInbox::InboxWritable->new($ibx)->importer(0); + my $V = $ibx->version; + my @eml = (glob('t/*.eml'), 't/data/0001.patch'); + for (@eml) { + next if $_ eq 't/psgi_v2-old.eml'; # dup mid + $im->add(eml_load($_)) or BAIL_OUT "v$V add $_"; + $seen++; + } + $im->done; + if ($V == 1) { + run_script(['-index', $ibx->{inboxdir}]) or + BAIL_OUT 'index v1'; + } + }); + $seen or BAIL_OUT 'no imports'; + open my $fh, '>', $stamp or BAIL_OUT "open $stamp: $!"; + @ret; +}; package PublicInboxTestProcess; use strict;