]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/lei.t
tests: add test_lei wrapper, split out t/lei-import.t
[public-inbox.git] / t / lei.t
diff --git a/t/lei.t b/t/lei.t
index 03bbb078ed09e71548b3cbc1372f6c10b6fbca2e..9f92d895b3be268816f691022ac67c01fb796b2b 100644 (file)
--- a/t/lei.t
+++ b/t/lei.t
@@ -9,6 +9,9 @@ use PublicInbox::Config;
 use File::Path qw(rmtree);
 use Fcntl qw(SEEK_SET);
 use PublicInbox::Spawn qw(which);
+my $req_sendcmd = 'Socket::MsgHdr or Inline::C missing or unconfigured';
+undef($req_sendcmd) if PublicInbox::Spawn->can('send_cmd4');
+eval { require Socket::MsgHdr; undef $req_sendcmd };
 require_git 2.6;
 require_mods(qw(json DBD::SQLite Search::Xapian));
 my $opt = { 1 => \(my $out = ''), 2 => \(my $err = '') };
@@ -38,7 +41,6 @@ local $ENV{GIT_COMMITTER_EMAIL} = 'lei@example.com';
 local $ENV{GIT_COMMITTER_NAME} = 'lei user';
 local $ENV{XDG_RUNTIME_DIR} = "$home/xdg_run";
 local $ENV{HOME} = $home;
-local $ENV{FOO} = 'BAR';
 mkdir "$home/xdg_run", 0700 or BAIL_OUT "mkdir: $!";
 my $home_trash = [ "$home/.local", "$home/.config", "$home/junk" ];
 my $cleanup = sub { rmtree([@$home_trash, @_]) };
@@ -165,6 +167,7 @@ my $test_external_remote = sub {
 SKIP: {
        my $nr = 5;
        skip "$k unset", $nr if !$url;
+       skip $req_sendcmd, $nr if $req_sendcmd;
        $curl or skip 'no curl', $nr;
        which('torsocks') or skip 'no torsocks', $nr if $url =~ m!\.onion/!;
        my $mid = '20140421094015.GA8962@dcvr.yhbt.net';
@@ -245,6 +248,8 @@ my $test_external = sub {
        $lei->('ls-external');
        unlike($out, qr!https://example\.com/ibx/!s, 'removed canonical URL');
 
+SKIP: {
+       skip $req_sendcmd, 52 if $req_sendcmd;
        ok(!$lei->(qw(q s:prefix -o /dev/null -f maildir)), 'bad maildir');
        like($err, qr!/dev/null exists and is not a directory!,
                'error shown');
@@ -275,6 +280,25 @@ my $test_external = sub {
        my $pretty = $json->decode($out);
        is_deeply($res, $pretty, '--pretty is identical after decode');
 
+       {
+               open my $fh, '+>', undef or BAIL_OUT $!;
+               $fh->autoflush(1);
+               print $fh 's:use' or BAIL_OUT $!;
+               seek($fh, 0, SEEK_SET) or BAIL_OUT $!;
+               ok($lei->([qw(q -q --stdin)], undef, { %$opt, 0 => $fh }),
+                               '--stdin on regular file works');
+               like($out, qr/use boolean prefix/, '--stdin on regular file');
+       }
+       {
+               pipe(my ($r, $w)) or BAIL_OUT $!;
+               print $w 's:use' or BAIL_OUT $!;
+               close $w or BAIL_OUT $!;
+               ok($lei->([qw(q -q --stdin)], undef, { %$opt, 0 => $r }),
+                               '--stdin on pipe file works');
+               like($out, qr/use boolean prefix/, '--stdin on pipe');
+       }
+       ok(!$lei->(qw(q -q --stdin s:use)), "--stdin and argv don't mix");
+
        for my $fmt (qw(ldjson ndjson jsonl)) {
                $lei->('q', '-f', $fmt, 's:use boolean prefix');
                is($out, $json->encode($pretty->[0])."\n", "-f $fmt");
@@ -323,6 +347,7 @@ my $test_external = sub {
                $url = $e{$k} if $url eq '1';
                $test_external_remote->($url, $k);
        }
+       }; # /SKIP
 };
 
 my $test_completion = sub {
@@ -337,7 +362,7 @@ my $test_completion = sub {
                        --mua --mua-cmd --no-local --local --verbose -v
                        --save-as --no-remote --remote --torsocks
                        --reverse -r )) {
-               ok($out{$sw}, "$sw offered as completion");
+               ok($out{$sw}, "$sw offered as `lei q' completion");
        }
 
        ok($lei->(qw(_complete lei q --form)), 'complete q --format');
@@ -350,14 +375,23 @@ my $test_completion = sub {
                        ok($out{$f}, "got $sw $f as output format");
                }
        }
+       ok($lei->(qw(_complete lei import)), 'complete import');
+       %out = map { $_ => 1 } split(/\s+/s, $out);
+       for my $sw (qw(--flags --no-flags --no-kw --kw --no-keywords
+                       --keywords)) {
+               ok($out{$sw}, "$sw offered as `lei import' completion");
+       }
 };
 
 my $test_fail = sub {
+SKIP: {
+       skip $req_sendcmd, 3 if $req_sendcmd;
        $lei->(qw(q --only http://127.0.0.1:99999/bogus/ t:m));
        is($? >> 8, 3, 'got curl exit for bogus URL');
        $lei->(qw(q --only http://127.0.0.1:99999/bogus/ t:m -o), "$home/junk");
        is($? >> 8, 3, 'got curl exit for bogus URL with Maildir');
        is($out, '', 'no output');
+}; # /SKIP
 };
 
 my $test_lei_common = sub {
@@ -378,10 +412,7 @@ if ($ENV{TEST_LEI_ONESHOT}) {
        $test_lei_common->();
 } else {
 SKIP: { # real socket
-       eval { require Socket::MsgHdr; 1 } // do {
-               require PublicInbox::Spawn;
-               PublicInbox::Spawn->can('send_cmd4');
-       } // skip 'Socket::MsgHdr or Inline::C missing or unconfigured', 115;
+       skip $req_sendcmd, 115 if $req_sendcmd;
        local $ENV{XDG_RUNTIME_DIR} = "$home/xdg_run";
        my $sock = "$ENV{XDG_RUNTIME_DIR}/lei/5.seq.sock";
        my $err_log = "$ENV{XDG_RUNTIME_DIR}/lei/errors.log";