### ----------------------------------------------------
### -- Elucid8::Build
### -- Licenses: Artistic-2.0
### -- Authors: Richard Hainsworth
### -- File: xt/15-install.rakutest
### ----------------------------------------------------
use v6.d;
use Test;
use File::Directory::Tree;
use Test::Run :runs_ok;

my $dir = 'test-directory';
if $dir.IO ~~ :e & :d {
    empty-directory $dir
}
else { mktree $dir }
my $cwd = $*CWD;
&chdir( $dir );
plan 6;
my @args = <<$*EXECUTABLE -I.. ../bin/elucid8-build>>;
runs_ok(
    'failure with no config and no install',
    :@args,
    :exitcode(1),
    :err( / 'Has another' .+ 'been created'/ )
);
@args.push: '--install';
runs_ok(
    'pass with install',
    :@args,
    :exitcode(0)
);
subtest 'config directories made' => {
    plan 4;
    for <config sources Misc sources/en> {
        ok .IO ~~ :e & :d, "$_ dir installed"
    }
}
@args.pop;
@args.push: '--config=qwert';
runs_ok(
    'failure with custom config and no install',
    :@args,
    :exitcode(1),
    :err( / 'Cannot proceed without directory ｢qwert｣.'/ )
);
@args.push: '--install';
runs_ok(
    'pass with install',
    :@args,
    :exitcode(0)
);
subtest 'custom config directories made' => {
    plan 4;
    for <qwert sources Misc sources/en> {
        ok .IO ~~ :e & :d, "$_ dir installed"
    }
}

&chdir( $cwd );
rmtree $dir;

done-testing;


