Skip to content

Commit cf27791

Browse files
committed
auto build t/ffi
1 parent 141edca commit cf27791

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

Changes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ Revision history for {{$dist->name}}
22

33
{{$NEXT}}
44
- Added ffi_options function (gh#3, gh#8)
5+
- ffi->test and ffi->combined will now build test lib
6+
if there is a t/ffi directory (gh#8)
57

68
0.05 2019-02-18 11:24:43 -0500
79
- Fix downstream install bug on Windows (gh#1)

lib/Test2/Tools/FFI.pm

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,45 @@ Returns a L<FFI::Platypus> instance connected to the test for your module.
210210
211211
=cut
212212

213+
sub _build_test
214+
{
215+
if(-d "t/ffi")
216+
{
217+
require FFI::Build::MM;
218+
require Capture::Tiny;
219+
220+
my($output, $error) = Capture::Tiny::capture_merged(sub {
221+
local $@ = '';
222+
eval {
223+
my $fbmm = FFI::Build::MM->new( save => 0 );
224+
$fbmm->mm_args( DISTNAME => "My-Test" ); # the DISTNAME isn't used for building the test anyway.
225+
$fbmm->test->build;
226+
};
227+
$@;
228+
});
229+
if($error)
230+
{
231+
my $ctx = Test2::API::context();
232+
$ctx->diag($error);
233+
$ctx->diag($output);
234+
$ctx->release;
235+
die $error;
236+
}
237+
else
238+
{
239+
my $ctx = Test2::API::context();
240+
$ctx->note($output);
241+
$ctx->release;
242+
}
243+
}
244+
}
245+
213246
sub test
214247
{
215248
my($self) = @_;
216249

217250
$self->{test} ||= do {
251+
_build_test();
218252
my $ffi = Test2::Tools::FFI::Platypus->new( @{ $self->{new_args} } );
219253
my @lib = FFI::CheckLib::find_lib(
220254
lib => '*',
@@ -241,6 +275,7 @@ sub combined
241275
my($self) = @_;
242276

243277
$self->{combined} ||= do {
278+
_build_test();
244279
my $rt = $self->runtime;
245280
my $t = $self->test;
246281
my $ffi = Test2::Tools::FFI::Platypus->new( @{ $self->{new_args} } );

t/00_diag.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ my %modules;
1010
my $post_diag;
1111

1212
$modules{$_} = $_ for qw(
13+
Capture::Tiny
1314
ExtUtils::MakeMaker
1415
FFI::Build
1516
FFI::Build::MM

0 commit comments

Comments
 (0)