+ # init tests
+ $out = $err = '';
+ my $ok_err_info = sub {
+ my ($msg) = @_;
+ is(grep(!/^I:/, split(/^/, $err)), 0, $msg) or
+ diag "$msg: err=$err";
+ $err = '';
+ };
+ my $home_trash = [ "$home/.local", "$home/.config" ];
+ rmtree($home_trash);
+ ok(run_script([qw(lei init)], undef, $opt), 'init w/o args');
+ $ok_err_info->('after init w/o args');
+ ok(run_script([qw(lei init)], undef, $opt), 'idempotent init w/o args');
+ $ok_err_info->('after idempotent init w/o args');
+
+ ok(!run_script([qw(lei init), "$home/x"], undef, $opt),
+ 'init conflict');
+ is(grep(/^E:/, split(/^/, $err)), 1, 'got error on conflict');
+ ok(!-e "$home/x", 'nothing created on conflict');
+ rmtree($home_trash);
+
+ $err = '';
+ ok(run_script([qw(lei init), "$home/x"], undef, $opt),
+ 'init conflict resolved');
+ $ok_err_info->('init w/ arg');
+ ok(run_script([qw(lei init), "$home/x"], undef, $opt),
+ 'init idempotent with path');
+ $ok_err_info->('init idempotent w/ arg');
+ ok(-d "$home/x", 'created dir');
+ rmtree([ "$home/x", @$home_trash ]);
+
+ $err = '';
+ ok(!run_script([qw(lei init), "$home/x", "$home/2" ], undef, $opt),
+ 'too many args fails');
+ like($err, qr/too many/, 'noted excessive');
+ ok(!-e "$home/x", 'x not created on excessive');
+ for my $d (@$home_trash) {
+ my $base = (split(m!/!, $d))[-1];
+ ok(!-d $d, "$base not created");
+ }
+ is($out, '', 'nothing in stdout');
+};
+
+SKIP: {
+ 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->();
+