-my $test_extinbox = sub {
- $setup_publicinboxes->();
- $cleanup->();
- $lei->('ls-extinbox');
- is($out.$err, '', 'ls-extinbox no output, yet');
- ok(!-e $config_file && !-e $store_dir,
- 'nothing created by ls-extinbox');
-
- my $cfg = PublicInbox::Config->new;
- $cfg->each_inbox(sub {
- my ($ibx) = @_;
- ok($lei->(qw(add-extinbox -q), $ibx->{inboxdir}),
- 'added extinbox');
- is($out.$err, '', 'no output');
- });
- ok(-s $config_file && -e $store_dir,
- 'add-extinbox created config + store');
- my $lcfg = PublicInbox::Config->new($config_file);
- $cfg->each_inbox(sub {
- my ($ibx) = @_;
- is($lcfg->{"extinbox.$ibx->{inboxdir}.boost"}, 0,
- "configured boost on $ibx->{name}");
- });
- $lei->('ls-extinbox');
- like($out, qr/boost=0\n/s, 'ls-extinbox has output');
-};
-
-my $test_lei_common = sub {
- $test_help->();
- $test_config->();
- $test_init->();
- $test_extinbox->();
-};
-
-my $test_lei_oneshot = $ENV{TEST_LEI_ONESHOT};
-SKIP: {
- last SKIP if $test_lei_oneshot;
- require_mods(qw(IO::FDPass Cwd), 46);
- my $sock = "$ENV{XDG_RUNTIME_DIR}/lei/sock";
-
- ok(run_script([qw(lei daemon-pid)], undef, $opt), 'daemon-pid');
- is($err, '', 'no error from daemon-pid');
- like($out, qr/\A[0-9]+\n\z/s, 'pid returned') or BAIL_OUT;
- chomp(my $pid = $out);
- ok(kill(0, $pid), 'pid is valid');
- ok(-S $sock, 'sock created');
-
- $test_lei_common->();
-
- $out = '';
- ok(run_script([qw(lei daemon-pid)], undef, $opt), 'daemon-pid');
- chomp(my $pid_again = $out);
- is($pid, $pid_again, 'daemon-pid idempotent');
-
- $out = '';
- ok(run_script([qw(lei daemon-env -0)], undef, $opt), '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');
-
- $out = '';
- ok(run_script([qw(lei daemon-env -u FOO)], undef, $opt), 'unset');
- is($out.$err, '', 'no output for unset');
- ok(run_script([qw(lei daemon-env -0)], undef, $opt), 'show again');
- is($err, '', 'no errors in env dump');
- @env = split(/\0/, $out);
- is(scalar grep(/\AFOO=BAR\z/, @env), 0, 'env unset FOO');
-
- $out = '';
- ok(run_script([qw(lei daemon-env -u FOO -u HOME -u XDG_RUNTIME_DIR)],
- undef, $opt), 'unset multiple');
- is($out.$err, '', 'no errors output for unset');
- ok(run_script([qw(lei daemon-env -0)], undef, $opt), '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@');
- $out = '';
- ok(run_script([qw(lei daemon-env -)], undef, $opt), 'clear env');
- is($out.$err, '', 'no output');
- ok(run_script([qw(lei daemon-env)], undef, $opt), 'env is empty');
- is($out, '', 'env cleared');
-
- ok(run_script([qw(lei daemon-kill)], undef, $opt), 'daemon-kill');
- is($out, '', 'no output from daemon-kill');
- is($err, '', 'no error from daemon-kill');
- for (0..100) {
- kill(0, $pid) or last;
- tick();
- }
- ok(!-S $sock, 'sock gone');
- ok(!kill(0, $pid), 'pid gone after stop');
-
- ok(run_script([qw(lei daemon-pid)], undef, $opt), 'daemon-pid');
- chomp(my $new_pid = $out);
- ok(kill(0, $new_pid), 'new pid is running');
- ok(-S $sock, 'sock exists again');
-
- $out = $err = '';
- for my $sig (qw(-0 -CHLD)) {
- ok(run_script([qw(lei daemon-kill), $sig ], undef, $opt),
- "handles $sig");