### ----------------------------------------------------
### -- Mi6::Helper
### -- Licenses: Artistic-2.0
### -- Authors: Tom Browder <tbrowder@acm.org>
### -- File: xt/3-helper-new.rakutest
### ----------------------------------------------------
use Test;

use Mi6::Helper;
use File::Temp;
use App::Mi6;
use JSON::Fast;
use File::Directory::Tree;
use Proc::Easier;

# check the system for known values used for fez and mi6
my $tdir = tempdir;

my $oo          = Mi6::Helper.new: :module-name("null"), :parent-dir($tdir);
my %fez         = App::Mi6::JSON.decode(slurp "$*HOME/.fez-config.json");
my $auth        = "zef:{%fez<un>}";
my $email       = $oo.git-user-email;
my $author      = $oo.git-user-name;
my $meta-author = "$author \<$email\>";

my $debug = 0;

# provide a unique testing directory by test file name
my $debug-base = "debug-test";
my $debug-dir  = $debug-base ~ '/' ~ $?FILE.IO.basename;

# remove the trailing '.t*'
$debug-dir ~~ s/'.t'$//;

rmtree $debug-dir if $debug-dir.IO.d;

my ($res, $gs, $proc);

if not $debug {
    # normal testing
    $tdir = tempdir;
}
else {
    # development testing: preserves the output in dir '$tdir'
    mkdir $debug-dir;
    $tdir = $debug-dir;
}

ok $tdir.IO.d;

{
    # home info for a fez user is in file $HOME/.fez-config.json;
    #   "un" : "SOMEBODY",
    #   "key" : "some-hash-key",

    chdir $tdir;

    #run "touch", '.Foo-Bar';
    cmd "touch '.Foo-Bar'";

    my $module-name = 'Foo::Bar';
    my $parent-dir  = "."; #$tempdir;
    my $provides    = "Provides a framistan";

    if $debug {
        note "DEBUG: module-name: $module-name";
        note "DEBUG: parent-dir: $parent-dir";
    }

    =begin comment
    mi6-helper-new(:$parent-dir, :$module-name, :$provides, :$debug);
    my $moddir = $module-name;
    $moddir ~~ s:g/'::'/-/;
    ok $moddir.IO.d;

    # check the meta file for known values
    my %meta = App::Mi6::JSON.decode(slurp "$moddir/META6.json");
    is %meta<auth>, $auth, "is auth $auth?";
    #is @(%meta<authors>)[0], $author, "is author 1 $author?";
    =end comment
}

done-testing;


