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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
use lib 't/lib';
use Test2::V0 -no_srand => 1;
use Test2::Plugin::FauxOS 'MSWin32';
use FFI::CheckLib;
use Env qw( @PATH );
@$FFI::CheckLib::system_path = (
'corpus/windows/bin',
);
subtest 'find_lib (good)' => sub {
my($path) = find_lib( lib => 'dinosaur' );
ok -r $path, "path = $path is readable";
my $path2 = find_lib( lib => 'dinosaur' );
is $path, $path2, 'scalar context';
};
subtest 'find_lib (fail)' => sub {
my @path = find_lib( lib => 'foobar' );
ok @path == 0, 'libfoobar not found';
};
subtest 'find_lib (good) with lib and version' => sub {
my($path) = find_lib( lib => 'apatosaurus' );
ok -r $path, "path = $path is readable";
my $path2 = find_lib( lib => 'apatosaurus' );
is $path, $path2, 'scalar context';
};
subtest 'in sync with $ENV{PATH}' => sub {
local $ENV{PATH} = $ENV{PATH};
@PATH = qw( foo bar baz );
is(
$FFI::CheckLib::system_path,
[qw( foo bar baz )],
);
};
subtest 'lib with name like libname-1-2-3.dll' => sub {
my($path) = find_lib( lib => 'maiasaura' );
ok -r $path, "path = $path is readable";
my $path2 = find_lib( lib => 'maiasaura' );
is $path, $path2, 'scalar context';
};
subtest 'lib with name like name-1-2-3.dll' => sub {
my($path) = find_lib( lib => 'dromornis_planei' );
ok -r $path, "path = $path is readable";
my $path2 = find_lib( lib => 'dromornis_planei' );
is $path, $path2, 'scalar context';
};
subtest 'lib with name like libname-1-2___.dll' => sub {
my($path) = find_lib( lib => 'thylacaleo_carnifex' );
ok -r $path, "path = $path is readable";
my $path2 = find_lib( lib => 'thylacaleo_carnifex' );
is $path, $path2, 'scalar context';
};
subtest 'lib with name like libname_1_2.dll' => sub {
my($path) = find_lib( lib => 'brevipalatus_mcculloughi' );
ok -r $path, "path = $path is readable";
my $path2 = find_lib( lib => 'brevipalatus_mcculloughi' );
is $path, $path2, 'scalar context';
};
subtest 'lib with name like libname_ext.dll' => sub {
my($path) = find_lib( lib => 'apatosaurus_ajax' );
ok -r $path, "path = $path is readable";
my $path2 = find_lib( lib => 'apatosaurus_ajax' );
is $path, $path2, 'scalar context';
};
sub p
{
my($path) = @_;
$path =~ s{/}{\\}g if $^O eq 'MSWin32';
$path;
}
subtest '_cmp' => sub {
my $process = sub {
[
sort { FFI::CheckLib::_cmp($a,$b) }
map { FFI::CheckLib::_matches($_, 'C:/bin') }
@_
];
};
is(
$process->(qw( foo-1.dll bar-2.dll baz-0.dll )),
[
[ 'bar', p('C:/bin/bar-2.dll'), 2 ],
[ 'baz', p('C:/bin/baz-0.dll'), 0 ],
[ 'foo', p('C:/bin/foo-1.dll'), 1 ],
],
'name first 1',
);
is(
$process->(qw( baz-0.dll foo-1.dll bar-2.dll )),
[
[ 'bar', p('C:/bin/bar-2.dll'), 2 ],
[ 'baz', p('C:/bin/baz-0.dll'), 0 ],
[ 'foo', p('C:/bin/foo-1.dll'), 1 ],
],
'name first 1',
);
is(
$process->(qw( bar-2.dll foo-1.dll baz-0.dll )),
[
[ 'bar', p('C:/bin/bar-2.dll'), 2 ],
[ 'baz', p('C:/bin/baz-0.dll'), 0 ],
[ 'foo', p('C:/bin/foo-1.dll'), 1 ],
],
'name first 1',
);
is(
$process->(qw( foo-2.dll foo-0.dll foo-1.dll )),
[
[ 'foo', p('C:/bin/foo-2.dll'), 2, ],
[ 'foo', p('C:/bin/foo-1.dll'), 1, ],
[ 'foo', p('C:/bin/foo-0.dll'), 0, ],
],
'newer version first',
);
};
subtest 'case insensitive' => sub {
local $FFI::CheckLib::system_path = [ 'corpus/windows/bincase' ];
subtest 'no prefix' => sub {
my($path) = find_lib( lib => 'foo' );
ok $path;
note "path = @{[ defined $path ? $path : 'undef' ]}";
};
subtest 'with lib prefix' => sub {
my($path) = find_lib( lib => 'bar' );
ok $path;
note "path = @{[ defined $path ? $path : 'undef' ]}";
};
};
done_testing;
|