-my $test_lei_oneshot = $ENV{TEST_LEI_ONESHOT};
-SKIP: {
- last SKIP if $test_lei_oneshot;
- require_mods('IO::FDPass', 16);
- 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-stop)], undef, $opt), 'daemon-stop');
- is($out, '', 'no output from daemon-stop');
- is($err, '', 'no error from daemon-stop');
- for (0..100) {
- kill(0, $pid) or last;
- tick();
+my $test_completion = sub {
+ lei_ok(qw(_complete lei), \'no errors on complete');
+ my %out = map { $_ => 1 } split(/\s+/s, $lei_out);
+ ok($out{'q'}, "`lei q' offered as completion");
+ ok($out{'add-external'}, "`lei add-external' offered as completion");
+
+ lei_ok(qw(_complete lei q), \'complete q (no args)');
+ %out = map { $_ => 1 } split(/\s+/s, $lei_out);
+ for my $sw (qw(-f --format -o --output --mfolder --augment -a
+ --mua --no-local --local --verbose -v
+ --save --no-save --no-remote --remote --torsocks
+ --reverse -r )) {
+ ok($out{$sw}, "$sw offered as `lei q' completion");
+ }
+
+ lei_ok(qw(_complete lei q --form), \'complete q --format');
+ is($lei_out, "--format\n", 'complete lei q --format');
+ for my $sw (qw(-f --format)) {
+ lei_ok(qw(_complete lei q), $sw);
+ %out = map { $_ => 1 } split(/\s+/s, $lei_out);
+ for my $f (qw(mboxrd mboxcl2 mboxcl mboxo json jsonl
+ concatjson maildir)) {
+ ok($out{$f}, "got $sw $f as output format");
+ }