### ----------------------------------------------------
### -- SuperMAIN
### -- Licenses: Artistic-2.0
### -- Authors: Claudio Ramirez <pub.claudio@gmail.com>
### -- File: t/02-multimainopts.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-multi.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-multi.raku', 'pos1', 'pos2', '--named=named',
        '--other-named=other-named', '--diff-named=diff-named', :out, :err;
is $proc.exitcode, 0, "named-anywhere";

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

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


$proc = run 't/supermain-multi.raku', 'pos1', 'pos2', '--named', 'named',
        '-o', 'other-named', :out, :err;
is $proc.exitcode, 0, "autoalias shortest";
$std-out = $proc.out.slurp: :close;
like $std-out.chomp, / << NAMED\: \s+ \[named\] .+ >>/, "check value";
like $std-out.chomp, / << OTHER\-NAMED\: \s+ \[other\-named\] /, "check value";

$proc = run 't/supermain-multi.raku', 'pos1', 'pos2',
        '--named', 'named', '-oth', 'other-named', '-ott', 'otter-named',
        :out, :err;
is $proc.exitcode, 0, "autoalias multi match";
$std-out = $proc.out.slurp: :close;
like $std-out.chomp, / << NAMED\: \s+ \[named\] .+ >>/, "check value";
like $std-out.chomp, / << OTHER\-NAMED\: \s+ \[other\-named\] .+ >>/, "check value";
like $std-out.chomp, / << OTTER\-NAMED\: \s+ \[otter\-named\] /, "check value";

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

done-testing;


