### ----------------------------------------------------
### -- Pakku
### -- Licenses: Artistic-2.0
### -- Authors: Haytham Elganiny
### -- File: t/core.rakutest
### ----------------------------------------------------
#!/usr/bin/env raku

use Test;

use Pakku::Core;

my $core;

lives-ok {
  $core =
  class {
    also does Pakku::Core;

    submethod BUILD( :%!cnf ) {

      my $stage  = $*TMPDIR.add( '.pakku' ).add( 'stage' ).add( rand );

      my @recman = ( %( :name<pakku>, :location<http://recman.pakku.org>, :1priority, :active ), );

      $!log    = Pakku::Log.new: :verbose<nothing>;

			my $http = Pakku::HTTP.new;

			$!recman = Pakku::Recman.new: :$http :@recman;

			@!repo = $*REPO.repo-chain.grep( CompUnit::Repository::Installation );

    }
  } .new
}, 'Compose Pakku::Core';

ok  $core.satisfied( spec => Pakku::Spec.new( { any => [ "archive:ver<13>:from<native>", "archive:from<native>" ] } ) ), 'Native dependency exists' if $*KERNEL ~~ 'linux';
nok $core.satisfied( spec => Pakku::Spec.new( { :from<native>, :name<missing> } ) ), 'Native dependency missing';

ok  $core.satisfied( spec => Pakku::Spec.new( { :from<bin>, :name<raku>    } ) ), 'Binary dependency exists';
nok $core.satisfied( spec => Pakku::Spec.new( { :from<bin>, :name<missing> } ) ), 'Binary dependency missing';

ok  $core.satisfied( spec => Pakku::Spec.new( 'rakudo'          ) ), 'Raku dependency exists';
nok $core.satisfied( spec => Pakku::Spec.new( 'rakudo:ver<-42>' ) ), 'Raku dependency missing';

dies-ok  { $core.satisfy( spec => Pakku::Spec.new( { :from<native>, :name<archive> } ) ) }, 'Native dependency no satisfy';
dies-ok  { $core.satisfy( spec => Pakku::Spec.new( { :from<bin>,    :name<raku>    } ) ) }, 'Binary dependency no satisfy';


lives-ok {

$core.satisfy( spec => Pakku::Spec.new( { any => <foo bar Pakku baz> } ) );

}, 'Can satisfy a dependency';

dies-ok {
  $core.satisfy( spec => Pakku::Spec.new( 'foobarbaz:from<Native>' ) );
	}, 'can not satisfy bin dependency';

done-testing;


