]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/lei.t
lei: pass FD to CWD via cmsg, use fchdir on server
[public-inbox.git] / t / lei.t
diff --git a/t/lei.t b/t/lei.t
index 42c0eb8ff22b790e9213acc43c9dba5ec712dc13..2349dca41e3dd304c426110c063b39c38b53d242 100644 (file)
--- a/t/lei.t
+++ b/t/lei.t
@@ -10,6 +10,8 @@ use File::Path qw(rmtree);
 require_git 2.6;
 require_mods(qw(json DBD::SQLite Search::Xapian));
 my $opt = { 1 => \(my $out = ''), 2 => \(my $err = '') };
+my ($home, $for_destroy) = tmpdir();
+my $err_filter;
 my $lei = sub {
        my ($cmd, $env, $xopt) = @_;
        $out = $err = '';
@@ -17,10 +19,12 @@ my $lei = sub {
                ($env, $xopt) = grep { (!defined) || ref } @_;
                $cmd = [ grep { defined && !ref } @_ ];
        }
-       run_script(['lei', @$cmd], $env, $xopt // $opt);
+       my $res = run_script(['lei', @$cmd], $env, $xopt // $opt);
+       $err_filter and
+               $err = join('', grep(!/$err_filter/, split(/^/m, $err)));
+       $res;
 };
 
-my ($home, $for_destroy) = tmpdir();
 delete local $ENV{XDG_DATA_HOME};
 delete local $ENV{XDG_CONFIG_HOME};
 local $ENV{GIT_COMMITTER_EMAIL} = 'lei@example.com';
@@ -122,7 +126,7 @@ my $setup_publicinboxes = sub {
        return if $done eq $home;
        use PublicInbox::InboxWritable;
        for my $V (1, 2) {
-               run_script([qw(-init -Lmedium), "-V$V", "t$V",
+               run_script([qw(-init), "-V$V", "t$V",
                                '--newsgroup', "t.$V",
                                "$home/t$V", "http://example.com/t$V",
                                "t$V\@example.com" ]) or BAIL_OUT "init v$V";
@@ -175,6 +179,15 @@ my $test_external = sub {
        });
        $lei->('ls-external');
        like($out, qr/boost=0\n/s, 'ls-external has output');
+
+       # note, on a Bourne shell users should be able to use either:
+       #       s:"use boolean prefix"
+       #       "s:use boolean prefix"
+       # or use single quotes, it should not matter.  Users only need
+       # to know shell quoting rules, not Xapian quoting rules.
+       # No double-quoting should be imposed on users on the CLI
+       $lei->('q', 's:use boolean prefix');
+       like($out, qr/search: use boolean prefix/, 'phrase search got result');
 };
 
 my $test_lei_common = sub {
@@ -186,19 +199,23 @@ my $test_lei_common = sub {
 
 if ($ENV{TEST_LEI_ONESHOT}) {
        require_ok 'PublicInbox::LEI';
-       # force sun_path[108] overflow, "IO::FDPass" avoids warning
-       local $ENV{XDG_RUNTIME_DIR} = "$home/IO::FDPass".('.sun_path' x 108);
+       # force sun_path[108] overflow, ($lei->() filters out this path)
+       my $xrd = "$home/1shot-test".('.sun_path' x 108);
+       local $ENV{XDG_RUNTIME_DIR} = $xrd;
+       $err_filter = qr!\Q$xrd!;
        $test_lei_common->();
 }
 
 SKIP: { # real socket
-       require_mods(qw(Cwd), my $nr = 46);
-       require PublicInbox::Spawn;
-       skip "Inline::C not installed/configured or IO::FDPass missing", $nr
-               unless PublicInbox::Spawn->can('send_3fds');
+       require_mods(qw(Cwd), my $nr = 105);
+       my $nfd = eval { require Socket::MsgHdr; 5 } // do {
+               require PublicInbox::Spawn;
+               PublicInbox::Spawn->can('send_cmd4') ? 5 : undef;
+       } //
+       skip 'Socket::MsgHdr or Inline::C missing or unconfigured', $nr;
 
        local $ENV{XDG_RUNTIME_DIR} = "$home/xdg_run";
-       my $sock = "$ENV{XDG_RUNTIME_DIR}/lei/sock";
+       my $sock = "$ENV{XDG_RUNTIME_DIR}/lei/$nfd.seq.sock";
 
        ok($lei->('daemon-pid'), 'daemon-pid');
        is($err, '', 'no error from daemon-pid');
@@ -213,34 +230,6 @@ SKIP: { # real socket
        chomp(my $pid_again = $out);
        is($pid, $pid_again, 'daemon-pid idempotent');
 
-       ok($lei->(qw(daemon-env -0)), 'show env');
-       is($err, '', 'no errors in env dump');
-       my @env = split(/\0/, $out);
-       is(scalar grep(/\AHOME=\Q$home\E\z/, @env), 1, 'env has HOME');
-       is(scalar grep(/\AFOO=BAR\z/, @env), 1, 'env has FOO=BAR');
-       is(scalar grep(/\AXDG_RUNTIME_DIR=/, @env), 1, 'has XDG_RUNTIME_DIR');
-
-       ok($lei->(qw(daemon-env -u FOO)), 'unset');
-       is($out.$err, '', 'no output for unset');
-       ok($lei->(qw(daemon-env -0)), 'show again');
-       is($err, '', 'no errors in env dump');
-       @env = split(/\0/, $out);
-       is(scalar grep(/\AFOO=BAR\z/, @env), 0, 'env unset FOO');
-
-       ok($lei->(qw(daemon-env -u FOO -u HOME -u XDG_RUNTIME_DIR)),
-                       'unset multiple');
-       is($out.$err, '', 'no errors output for unset');
-
-       ok($lei->(qw(daemon-env -0)), 'show again');
-       is($err, '', 'no errors in env dump');
-       @env = split(/\0/, $out);
-       is(scalar grep(/\A(?:HOME|XDG_RUNTIME_DIR)=\z/, @env), 0, 'env unset@');
-
-       ok($lei->(qw(daemon-env -)), 'clear env');
-       is($out.$err, '', 'no output');
-       ok($lei->(qw(daemon-env)), 'env is empty');
-       is($out, '', 'env cleared');
-
        ok($lei->(qw(daemon-kill)), 'daemon-kill');
        is($out, '', 'no output from daemon-kill');
        is($err, '', 'no error from daemon-kill');
@@ -248,13 +237,13 @@ SKIP: { # real socket
                kill(0, $pid) or last;
                tick();
        }
-       ok(!-S $sock, 'sock gone');
+       ok(-S $sock, 'sock still exists');
        ok(!kill(0, $pid), 'pid gone after stop');
 
        ok($lei->(qw(daemon-pid)), 'daemon-pid');
        chomp(my $new_pid = $out);
        ok(kill(0, $new_pid), 'new pid is running');
-       ok(-S $sock, 'sock exists again');
+       ok(-S $sock, 'sock still exists');
 
        for my $sig (qw(-0 -CHLD)) {
                ok($lei->('daemon-kill', $sig), "handles $sig");
@@ -271,29 +260,6 @@ SKIP: { # real socket
                like($out, qr/^usage: /, 'help output works');
                chmod 0700, $sock or BAIL_OUT "chmod 0700: $!";
        }
-       if ('oneshot on cwd gone') {
-               my $cwd = Cwd::fastcwd() or BAIL_OUT "fastcwd: $!";
-               my $d = "$home/to-be-removed";
-               my $lei_path = 'lei';
-               # we chdir, so we need an abs_path fur run_script
-               if (($ENV{TEST_RUN_MODE}//2) != 2) {
-                       $lei_path = PublicInbox::TestCommon::key2script('lei');
-                       $lei_path = Cwd::abs_path($lei_path);
-               }
-               mkdir $d or BAIL_OUT "mkdir($d) $!";
-               chdir $d or BAIL_OUT "chdir($d) $!";
-               if (rmdir($d)) {
-                       $out = $err = '';
-                       ok(run_script([$lei_path, 'help'], undef, $opt),
-                               'cwd fail, one-shot fallback works');
-               } else {
-                       $err = "rmdir=$!";
-               }
-               chdir $cwd or BAIL_OUT "chdir($cwd) $!";
-               like($err, qr/cwd\(/, 'cwd error noted');
-               like($out, qr/^usage: /, 'help output still works');
-       }
-
        unlink $sock or BAIL_OUT "unlink($sock) $!";
        for (0..100) {
                kill('CHLD', $new_pid) or last;