X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FTestCommon.pm;h=9e15239465aabe05728603b3db8869f48f128b7c;hb=0c385e6500f26babc47a0768b730ea38e290a5f5;hp=d28b32b07571f5ac28778d2dcd60fa36266c50f6;hpb=fc7b32789a8d223e6550d9315216833fa602bd22;p=public-inbox.git diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm index d28b32b0..9e152394 100644 --- a/lib/PublicInbox/TestCommon.pm +++ b/lib/PublicInbox/TestCommon.pm @@ -18,7 +18,7 @@ BEGIN { run_script start_script key2sub xsys xsys_e xqx eml_load tick have_xapian_compact json_utf8 setup_public_inboxes create_inbox tcp_host_port test_lei lei lei_ok $lei_out $lei_err $lei_opt - test_httpd xbail); + test_httpd xbail require_cmd is_xdeeply); require Test::More; my @methods = grep(!/\W/, @Test::More::EXPORT); eval(join('', map { "*$_=\\&Test::More::$_;" } @methods)); @@ -87,6 +87,18 @@ sub tcp_connect { $s; } +sub require_cmd ($;$) { + my ($cmd, $maybe) = @_; + require PublicInbox::Spawn; + my $bin = PublicInbox::Spawn::which($cmd); + return $bin if $bin; + $maybe ? 0 : plan(skip_all => "$cmd missing from PATH for $0"); +} + +sub have_xapian_compact () { + require_cmd($ENV{XAPIAN_COMPACT} || 'xapian-compact', 1); +} + sub require_git ($;$) { my ($req, $maybe) = @_; my ($req_maj, $req_min, $req_sub) = split(/\./, $req); @@ -144,7 +156,7 @@ sub require_mods { eval "require $mod"; } if ($@) { - diag "require $mod: $@"; + diag "require $mod: $@" if $mod =~ /Gcf2/; push @need, $mod; } elsif ($mod eq 'IO::Socket::SSL' && # old versions of IO::Socket::SSL aren't supported @@ -467,12 +479,6 @@ 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'); -} - # favor lei() or lei_ok() over $lei for new code sub lei (@) { my ($cmd, $env, $xopt) = @_; @@ -514,6 +520,13 @@ sub json_utf8 () { state $x = ref(PublicInbox::Config->json)->new->utf8->canonical; } +sub is_xdeeply ($$$) { + my ($x, $y, $desc) = @_; + my $ok = is_deeply($x, $y, $desc); + diag explain([$x, '!=', $y]) if !$ok; + $ok; +} + sub test_lei { SKIP: { my ($cb) = pop @_; @@ -561,7 +574,10 @@ SKIP: { } local $ENV{XDG_RUNTIME_DIR} = $daemon_xrd; $cb->(); - unless ($persist) { + if ($persist) { # remove before ~/.local gets removed + File::Path::rmtree([glob("$home/*")]); + File::Path::rmtree("$home/.config"); + } else { lei_ok(qw(daemon-pid), \"daemon-pid after $t"); chomp($daemon_pid = $lei_out); if (!$daemon_pid) { @@ -581,7 +597,7 @@ SKIP: { my $f = "$daemon_xrd/lei/errors.log"; open my $fh, '<', $f or BAIL_OUT "$f: $!"; my @l = <$fh>; - is_deeply(\@l, [], + is_xdeeply(\@l, [], "$t daemon XDG_RUNTIME_DIR/lei/errors.log empty"); } }; # SKIP if missing git 2.6+ || Xapian || SQLite || json