### ----------------------------------------------------
### -- Proc::Easier
### -- Licenses: Artistic-2.0
### -- Authors: Steve Dondley
### -- File: t/01-basic.rakutest
### ----------------------------------------------------
use Test;
use Test::Output;
use Proc::Easier;

plan 16;

lives-ok { Proc::Easier.new(cmd => 'ls', :lazy) }, 'creates object using standard constructor notation';
lives-ok { cmd 'ls' }, 'creates object using simplified interface';

if $*DISTRO.is-win {
    is (cmd 'cmd.exe /c dir').cmd, 'cmd.exe /c dir', 'cmd attribute set';
    like cmd('cmd.exe /c dir').out, /README/, 'sets/get output';
} else {
    is (cmd 'ls').cmd, 'ls', 'cmd attribute set';
    like cmd('ls').out, /README/, 'sets/get output';
}
is cmd('ls', :lazy).out, '', 'lazy works';
my $cmd = cmd 'ls';
lives-ok { $cmd.exit }, 'has exit method';
lives-ok { $cmd.exitcode }, 'has exit method';
is $cmd.caller-line, 18, 'get calling line number';
like $cmd.caller-file, /01\-basic\.rakutest/, 'get calling file name';
stdout-like { say $cmd }, rx:s/returned with exit code/, 'does gist';
$cmd = (cmd 'ls', :lazy).run;
is $cmd.caller-line, 24, 'get calling line number';
dies-ok { cmd 'kjkjsdfxxxxx', :die }, 'dies with bad command with :die';
lives-ok { cmd 'kjkjsdfxxxxx' }, 'deos not die with bad command, without :die';

autodie :on;
dies-ok { cmd 'kjkjsdfxxxxx' }, 'autodie on works';
autodie :off;
lives-ok { cmd 'kjkjsdfxxxxx' }, 'autodie off works';

if $*DISTRO.is-win {
    lives-ok { cmd 'cmd.exe /c dir', :die }, 'issues a real command';
} else {
    lives-ok { cmd 'ls', :die }, 'issues a real command';
}

done-testing;


