### ----------------------------------------------------
### -- Shell::Capture
### -- Licenses: Artistic-2.0
### -- Authors: Peter Pentchev
### -- File: t/01-simple.rakutest
### ----------------------------------------------------
#!/usr/bin/env raku

use v6.c;

use Test;

plan 13;

use lib 'lib';

use Shell::Capture;

my Shell::Capture $c .= capture($*EXECUTABLE, '-v');
is $c.exitcode, 0, 'raku -v succeeded';
isnt $c.lines.elems, 0, 'raku -v output something';

$c .= capture($*EXECUTABLE, '-e', 'say "Perl ahoy!"; exit 3');
is $c.exitcode, 3, 'raku -e exit 3 exited with 3';
is-deeply $c.lines, Array[Str].new('Perl ahoy!'),
    'raku -e "say" said the right thing';

my List:D $accept = (0, 7,);
my Int:D $failed-count = 0;

sub fail(Shell::Capture:D $r, @cmd)
{
	$failed-count++;
}

$c .= capture-check(:&fail, :$accept, $*EXECUTABLE, '-e', 'say ~$*EXECUTABLE');
is $failed-count, 0, 'failed count properly kept';
is $c.exitcode, 0, 'raku succeeded';
is-deeply $c.lines, Array[Str].new(~$*EXECUTABLE),
    'raku knows what its executable is';

$c .= capture-check(:&fail, :$accept, $*EXECUTABLE, '-e', 'exit 7');
is $failed-count, 0, 'failed count properly kept';
is $c.exitcode, 7, 'raku exited with 7';
is $c.lines.elems, 0, 'raku did not say anything';

$c .= capture-check(:&fail, :$accept,
    $*EXECUTABLE, '-e', 'say "a"; say "b"; exit 5');
is $failed-count, 1, 'failed count properly kept';
is $c.exitcode, 5, 'raku exited with 5';
is-deeply $c.lines, Array[Str].new(<a b>),
    'raku -e "say" said the right thing';


