Alien-Build

 view release on metacpan or  search on metacpan

t/alien_base.t  view on Meta::CPAN

use 5.008004;
use Test2::V0 -no_srand => 1;
use lib 'corpus/lib';
use Env qw( @PKG_CONFIG_PATH );
use File::Glob qw( bsd_glob );
use File::chdir;
use Path::Tiny qw( path );
use FFI::CheckLib;
use Text::ParseWords qw( shellwords );
use List::Util qw( first );

my $mock = mock 'FFI::CheckLib' => (
  override => [
    find_lib => sub {
      my %args = @_;
      my @libpath;
      if(ref $args{libpath})
      {
        @libpath = @{ $args{libpath} } if ref $args{libpath};
      }
      elsif(defined $args{libpath})
      {
        @libpath = ($args{libpath});
      }
      if(@libpath)
      {
        my @libs;
        foreach my $libpath (@libpath)
        {
          if($libpath eq '/roger/opt/libbumblebee/lib')
          {
            push @libs, '/roger/opt/libbumblebee/lib/libbumblebee.so';
            next;
          }
          next unless -d $libpath;
          local $CWD = $libpath;
          push @libs, map { path($_)->absolute->stringify } bsd_glob('*.so*');
        }
        return @libs;
      }
      else
      {
        if($args{lib} eq 'foo')
        {
          return ('/usr/lib/libfoo.so', '/usr/lib/libfoo.so.1');
        }
        else
        {
          return;
        }
      }
    },
  ],
);


unshift @PKG_CONFIG_PATH, path('corpus/pkgconfig')->absolute->stringify;

subtest 'AB::MB sys install' => sub {

  require Alien::Foo1;

  my $cflags  = Alien::Foo1->cflags;
  my $libs    = Alien::Foo1->libs;
  my $version = Alien::Foo1->version;

  $libs =~ s{^\s+}{};

  is $cflags, '-DFOO=stuff', "cflags: $cflags";
  is $libs,   '-lfoo1', "libs: $libs";
  is $version, '3.99999', "version: $version";
};

subtest 'AB::MB share install' => sub {

  require Alien::Base::PkgConfig;

  require Alien::Foo2;

  my $cflags  = Alien::Foo2->cflags;
  my $libs    = Alien::Foo2->libs;
  my $version = Alien::Foo2->version;

  ok $cflags,  "cflags: $cflags";
  ok $libs,    "libs:   $libs";
  is $version, '3.2.1', "version: $version";

  (first { /^-I/ } shellwords($cflags)) =~ /^-I(.*)$/;
  ok defined $1 && -f "$1/foo2.h", "include path";
  note "include path: $1";

  (first { /^-L/ } shellwords($libs)) =~ /^-L(.*)$/;
  ok defined $1 && -f "$1/libfoo2.a", "lib path";
  note "lib path: $1";

};



( run in 1.025 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )