use File::Path qw(rmtree);
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, $opt) = @_;
+ $out = $err = '';
+ if (!ref($cmd)) {
+ ($env, $opt) = grep { (!defined) || ref } @_;
+ $cmd = [ grep { defined } @_ ];
+ }
run_script([$LEI, @$cmd], $env, $opt);
};
my ($home, $for_destroy) = tmpdir();
-my $opt = { 1 => \(my $out = ''), 2 => \(my $err = '') };
delete local $ENV{XDG_DATA_HOME};
delete local $ENV{XDG_CONFIG_HOME};
local $ENV{XDG_RUNTIME_DIR} = "$home/xdg_run";
local $ENV{FOO} = 'BAR';
mkdir "$home/xdg_run", 0700 or BAIL_OUT "mkdir: $!";
my $home_trash = [ "$home/.local", "$home/.config" ];
-my $cleanup = sub {
- rmtree([@$home_trash, @_]);
- $out = $err = '';
-};
+my $cleanup = sub { rmtree([@$home_trash, @_]) };
my $test_help = sub {
ok(!$lei->([], undef, $opt), 'no args fails');
isnt($err, '', 'something in stderr');
is($out, '', 'nothing in stdout');
}
+ ok($lei->(qw(init -h), undef, $opt), 'init -h');
+ like($out, qr! \Q$home\E/\.local/share/lei/store\b!,
+ 'actual path shown in init -h');
+ ok($lei->(qw(init -h), { XDG_DATA_HOME => '/XDH' }, $opt),
+ 'init with XDG_DATA_HOME');
+ like($out, qr! /XDH/lei/store\b!, 'XDG_DATA_HOME in init -h');
+ is($err, '', 'no errors from init -h');
+
+ ok($lei->(qw(config -h), undef, $opt), 'config-h');
+ like($out, qr! \Q$home\E/\.config/lei/config\b!,
+ 'actual path shown in config -h');
+ ok($lei->(qw(config -h), { XDG_CONFIG_HOME => '/XDC' }, $opt),
+ 'config with XDG_CONFIG_HOME');
+ like($out, qr! /XDC/lei/config\b!, 'XDG_CONFIG_HOME in config -h');
+ is($err, '', 'no errors from config -h');
};
my $ok_err_info = sub {
my $test_lei_oneshot = $ENV{TEST_LEI_ONESHOT};
SKIP: {
last SKIP if $test_lei_oneshot;
- require_mods('IO::FDPass', 16);
+ require_mods(qw(IO::FDPass Cwd), 41);
my $sock = "$ENV{XDG_RUNTIME_DIR}/lei/sock";
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');
- unlink $sock or BAIL_OUT "unlink $!";
+
+ if ('socket inaccessible') {
+ chmod 0000, $sock or BAIL_OUT "chmod 0000: $!";
+ $out = $err = '';
+ ok(run_script([qw(lei help)], undef, $opt),
+ 'connect fail, one-shot fallback works');
+ like($err, qr/\bconnect\(/, 'connect error noted');
+ 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";
+ 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),
+ '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;
tick();