]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/lei-externals.t
lei: All Local Externals: bare git dir for alternates
[public-inbox.git] / t / lei-externals.t
index 296676409701c71e7f9542607fb039aafb7ce34f..2045691fa5c155a25e9891efdd7a5c2280c0b19c 100644 (file)
@@ -25,7 +25,7 @@ SKIP: {
        lei_ok(@cmd, \"query $url");
        is($lei_err, '', "no errors on $url");
        my $res = json_utf8->decode($lei_out);
-       is($res->[0]->{'m'}, "<$mid>", "got expected mid from $url") or
+       is($res->[0]->{'m'}, $mid, "got expected mid from $url") or
                skip 'further remote tests', 1;
        lei_ok(@cmd, 'd:..20101002', \'no results, no error');
        is($lei_err, '', 'no output on 404, matching local FS behavior');
@@ -78,8 +78,12 @@ test_lei(sub {
        ok(!-e $config_file && !-e $store_dir,
                'nothing created by ls-external');
 
-       ok(!lei('add-external', "$home/nonexistent",
-               "fails on non-existent dir"));
+       ok(!lei('add-external', "$home/nonexistent"),
+               "fails on non-existent dir");
+       like($lei_err, qr/not a directory/, 'noted non-existence');
+       mkdir "$home/new\nline" or BAIL_OUT "mkdir: $!";
+       ok(!lei('add-external', "$home/new\nline"), "fails on newline");
+       like($lei_err, qr/`\\n' not allowed/, 'newline noted in error');
        lei_ok('ls-external', \'ls-external works after add failure');
        is($lei_out.$lei_err, '', 'ls-external still has no output');
        my $cfg = PublicInbox::Config->new($cfg_path);
@@ -123,8 +127,10 @@ test_lei(sub {
        lei_ok qw(_complete lei forget-external), \'complete for externals';
        my %comp = map { $_ => 1 } split(/\s+/, $lei_out);
        ok($comp{'https://example.com/ibx/'}, 'forget external completion');
+       my @dirs;
        $cfg->each_inbox(sub {
                my ($ibx) = @_;
+               push @dirs, $ibx->{inboxdir};
                ok($comp{$ibx->{inboxdir}}, "local $ibx->{name} completion");
        });
        for my $u (qw(h http https https: https:/ https:// https://e
@@ -153,7 +159,8 @@ test_lei(sub {
        lei_ok('ls-external');
        unlike($lei_out, qr!https://example\.com/ibx/!s,
                'removed canonical URL');
-SKIP: {
+
+       # do some queries
        ok(!lei(qw(q s:prefix -o maildir:/dev/null)), 'bad maildir');
        like($lei_err, qr!/dev/null exists and is not a directory!,
                'error shown');
@@ -229,7 +236,8 @@ SKIP: {
                is(scalar(@s), 2, "2 results in mbox$sfx");
 
                lei_ok('q', '-a', '-o', "mboxcl2:$f", 's:nonexistent');
-               is(grep(!/^#/, $lei_err), 0, "no errors on no results ($sfx)");
+               is(grep(!/^#/, $lei_err), 0, "no errors on no results ($sfx)")
+                       or diag $lei_err;
 
                my @s2 = grep(/^Subject:/, $cat->());
                is_deeply(\@s2, \@s,
@@ -245,6 +253,15 @@ SKIP: {
        is($? >> 8, 1, 'proper exit code');
        like($lei_err, qr/no local or remote.+? to search/, 'no inbox');
 
+       for my $no (['--no-local'], ['--no-external'],
+                       [qw(--no-local --no-external)]) {
+               lei_ok(qw(q mid:testmessage@example.com), @$no,
+                       '-I', $dirs[0], \"-I and @$no combine");
+               $res = json_utf8->decode($lei_out);
+               is($res->[0]->{'m'}, 'testmessage@example.com',
+                       "-I \$DIR got results regardless of @$no");
+       }
+
        {
                opendir my $dh, '.' or BAIL_OUT "opendir(.) $!";
                my $od = PublicInbox::OnDestroy->new($$, sub {
@@ -274,6 +291,5 @@ SKIP: {
                $url = $e{$k} if $url eq '1';
                $test_external_remote->($url, $k);
        }
-       }; # /SKIP
 }); # test_lei
 done_testing;