### ----------------------------------------------------
### -- SuperMAIN
### -- Licenses: Artistic-2.0
### -- Authors: Claudio Ramirez <pub.claudio@gmail.com>
### -- File: t/01-submainopts.rakutest
### ----------------------------------------------------
use Test;
use lib 'lib';

# Skip test on Windows for now
if $*DISTRO.is-win {
    note "Windows testing skipped for now";
    done-testing;
    exit;
}

my $proc = run 't/supermain.raku', :out, :err;
isnt $proc.exitcode, 0, "no args (exitcode)";
my $std-err = $proc.err.slurp: :close;
like $std-err.chomp, /^^Usage\:/, "no args (output)";

$proc = run 't/supermain.raku', 'pos', '--named=named',
        '--other-named=other-named', :out, :err;
is $proc.exitcode, 0, "named-anywhere";

$proc = run 't/supermain.raku', 'pos', '-named=named',
        '--other-named=other-named', :out, :err;
is $proc.exitcode, 0, "named-anywhere, single '-'";

$proc = run 't/supermain.raku', 'pos1', '--named', 'named',
        '--other-named', 'other-named', '--bool', 'pos2', '-diff-bool',
        :out, :err;
is $proc.exitcode, 0, "space separated named param";
$std-err = $proc.out.slurp: :close;
like $std-err.chomp, / << POSITIONAL1\: \s+ \[pos1\] .+ >>/, "check value";
like $std-err.chomp, / << POSITIONAL2\: \s+ \[pos2\] .+ >>/, "check value";
like $std-err.chomp, / << NAMED\: \s+ \[named\] .+ >>/, "check value";
like $std-err.chomp, / << OTHER\-NAMED\: \s+ \[other\-named\] .+ >>/, "check value";
like $std-err.chomp, / << BOOL\: \s+ True >>/, "check value";
like $std-err.chomp, / << DIFF\-BOOL\: \s+ True >>/, "check value";

$proc = run 't/supermain.raku', 'pos1', '-n', 'named', '-o', 'other-named',
        '-b', 'pos2', '-d', :out, :err;
is $proc.exitcode, 0, "auto alias";
$std-err = $proc.out.slurp: :close;
like $std-err.chomp, / << POSITIONAL1\: \s+ \[pos1\] .+ >>/, "check value";
like $std-err.chomp, / << POSITIONAL2\: \s+ \[pos2\] .+ >>/, "check value";
like $std-err.chomp, / << NAMED\: \s+ \[named\] .+ >>/, "check value";
like $std-err.chomp, / << OTHER\-NAMED\: \s+ \[other\-named\] .+ >>/, "check value";
like $std-err.chomp, / << BOOL\: \s+ True >>/, "check value";
like $std-err.chomp, / << DIFF\-BOOL\: \s+ True >>/, "check value";

done-testing;


