1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
use 5.008004;
use lib 't/lib';
use MyTest::System;
use Test2::V0 -no_srand => 1;
use File::chdir;
use List::Util qw/shuffle/;
use Capture::Tiny qw( capture_merged );
use File::chdir;
use File::Temp qw( tempdir );
use Path::Tiny qw( path );
use Alien::Base::PkgConfig;
BEGIN { $ENV{ALIEN_FORCE} = 0; delete $ENV{ALIEN_INSTALL_TYPE} }
skip_all 'test requires Alien::Base::ModuleBuild'
unless (eval {
require Alien::Base::ModuleBuild;
Alien::Base::ModuleBuild->VERSION('0.040');
});
subtest 'basic' => sub {
# Since this is not a complete distribution, it complains about missing files/folders
local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /Can't (?:stat)|(?:find)/ };
local $CWD = tempdir( CLEANUP => 1 );
{
path('MANIFEST')->spew(
"lib/MyTest.pm\n",
"MANIFEST\t\t\tThis list of files\n",
);
path('lib')->mkpath;
path('lib/MyTest.pm')->spew(
"package MyTest;\n",
"\n",
"use strict;\n",
"use warnings;\n",
"use parent 'Alien::Base';\n",
"\n",
"1;\n",
);
}
my $lib = 'libfoo';
my $cflags = '-I/opt/foo/bar/baz/include';
my $libs = '-L/opt/foo/bar/baz/lib -lfoo';
my $gard = system_fake
'pkg-config' => sub {
my(@args) = @_;
if($args[0] eq '--modversion' && $args[1])
{
print "1.2.3\n";
return 0;
}
if($args[0] eq '--cflags' && $args[1])
{
print "$cflags \n";
return 0;
}
if($args[0] eq '--libs' && $args[1])
{
print "$libs \n";
return 0;
}
use Alien::Build::Util qw( _dump );
diag _dump(\@args);
ok 0, 'bad command';
return 2;
},
;
my $mock = mock 'Alien::Base::PkgConfig' => (
override => [
pkg_config_command => sub {
'pkg-config',
},
],
);
my $pkg_config = Alien::Base::PkgConfig->pkg_config_command;
note "lib = $lib\n";
note "cflags = $cflags\n";
note "libs = $libs\n";
my($builder) = do {
my($out, $builder) = capture_merged {
Alien::Base::ModuleBuild->new(
module_name => 'MyTest',
dist_version => 0.01,
alien_name => $lib,
share_dir => 't',
);
};
note $out;
$builder;
};
note scalar capture_merged { $builder->depends_on('build') };
{
local $CWD;
push @CWD, qw/blib lib/;
use lib '.';
require './MyTest.pm';
my $alien = MyTest->new;
isa_ok($alien, 'MyTest');
isa_ok($alien, 'Alien::Base');
note "alien->cflags = ", $alien->cflags;
note "alien->libs = ", $alien->libs;
is($alien->cflags, $cflags, "get cflags from system-installed library");
is($alien->libs , $libs , "get libs from system-installed library" );
}
note scalar capture_merged { $builder->depends_on('realclean') };
};
done_testing;
|