about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-12-31 17:47:48 -1200
committerEric Wong <e@80x24.org>2021-01-02 09:15:08 +0000
commitcc1660fd3bb16f684062d5c63ae4320d2c7f939c (patch)
treeeea53cdfad85c24eef9bea0f5e2bcbd73a47b806 /t
parent86851a5a264bc0e14e925982b09337ab32e20795 (diff)
downloadpublic-inbox-cc1660fd3bb16f684062d5c63ae4320d2c7f939c.tar.gz
We need to use an absolute path after chdir in run modes
where scripts aren't loaded into in-memory subs.

The oneshot test was also failing under TEST_RUN_MODE=0 due to
no "lei-oneshot" command existing on the FS.  So we force a
socket failure by making XDG_RUNTIME_DIR too large to fit into
the 108-byte .sun_path field of "struct sockaddr_un".  This
even lets us simplify lei-oneshot significantly.
Diffstat (limited to 't')
-rw-r--r--t/lei-oneshot.t17
-rw-r--r--t/lei.t29
2 files changed, 17 insertions, 29 deletions
diff --git a/t/lei-oneshot.t b/t/lei-oneshot.t
index 2b34f982..7688da5b 100644
--- a/t/lei-oneshot.t
+++ b/t/lei-oneshot.t
@@ -4,22 +4,5 @@
 use strict;
 use v5.10.1;
 use PublicInbox::TestCommon;
-$PublicInbox::TestCommon::cached_scripts{'lei-oneshot'} //= do {
-        eval <<'EOF';
-package LeiOneshot;
-use strict;
-use subs qw(exit);
-*exit = \&PublicInbox::TestCommon::run_script_exit;
-sub main {
-# the below "line" directive is a magic comment, see perlsyn(1) manpage
-# line 1 "lei-oneshot"
-        require PublicInbox::LEI;
-        PublicInbox::LEI::oneshot(__PACKAGE__);
-        0;
-}
-1;
-EOF
-        LeiOneshot->can('main');
-};
 local $ENV{TEST_LEI_ONESHOT} = '1';
 require './t/lei.t';
diff --git a/t/lei.t b/t/lei.t
index 690878ce..41638950 100644
--- a/t/lei.t
+++ b/t/lei.t
@@ -9,7 +9,6 @@ use PublicInbox::Config;
 use File::Path qw(rmtree);
 require_git 2.6;
 require_mods(qw(json DBD::SQLite Search::Xapian));
-my $LEI = 'lei';
 my $opt = { 1 => \(my $out = ''), 2 => \(my $err = '') };
 my $lei = sub {
         my ($cmd, $env, $xopt) = @_;
@@ -18,13 +17,12 @@ my $lei = sub {
                 ($env, $xopt) = grep { (!defined) || ref } @_;
                 $cmd = [ grep { defined && !ref } @_ ];
         }
-        run_script([$LEI, @$cmd], $env, $xopt // $opt);
+        run_script(['lei', @$cmd], $env, $xopt // $opt);
 };
 
 my ($home, $for_destroy) = tmpdir();
 delete local $ENV{XDG_DATA_HOME};
 delete local $ENV{XDG_CONFIG_HOME};
-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: $!";
@@ -188,10 +186,16 @@ my $test_lei_common = sub {
         $test_external->();
 };
 
-my $test_lei_oneshot = $ENV{TEST_LEI_ONESHOT};
-SKIP: {
-        last SKIP if $test_lei_oneshot;
+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);
+        $test_lei_common->();
+}
+
+SKIP: { # real socket
         require_mods(qw(IO::FDPass Cwd), 46);
+        local $ENV{XDG_RUNTIME_DIR} = "$home/xdg_run";
         my $sock = "$ENV{XDG_RUNTIME_DIR}/lei/sock";
 
         ok(run_script([qw(lei daemon-pid)], undef, $opt), 'daemon-pid');
@@ -275,11 +279,17 @@ SKIP: {
         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([qw(lei help)], undef, $opt),
+                        ok(run_script([$lei_path, 'help'], undef, $opt),
                                 'cwd fail, one-shot fallback works');
                 } else {
                         $err = "rmdir=$!";
@@ -296,11 +306,6 @@ SKIP: {
         }
         ok(!kill(0, $new_pid), 'daemon exits after unlink');
         # success over socket, can't test without
-        $test_lei_common = undef;
 };
 
-require_ok 'PublicInbox::LEI';
-$LEI = 'lei-oneshot' if $test_lei_oneshot;
-$test_lei_common->() if $test_lei_common;
-
 done_testing;