blib/lib/Test/Alien.pm

filter: Statementstmt 81.3% 383 / 471 Branchbran 68.2% 127 / 186 Conditioncond 54.2% 58 / 107 MC/DCmcdc 26.9% 17 / 63 Subroutinesub 95.1% 39 / 41 Podpod 90.0% 9 / 10 totaltotal 72.1% 633 / 878 CC 145 SCAR 45.8
CC
145
Cov
74%
ffi_ok
552.0
xs_ok
91.5
plugin_ok
14.7
CRAP 97.2
« blib/lib/Alien/Build/Plugin/Fetch/NetFTP.pm ↑ Summary blib/lib/Alien/Build/Plugin/PkgConfig/LibPkgConf.pm »
1 package Test::Alien;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Env qw( @PATH );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use File::Which 1.10 qw( which );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Capture::Tiny qw( capture capture_merged );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Alien::Build::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use File::Copy qw( move );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use Text::ParseWords qw( shellwords );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use Test2::API qw( context run_subtest );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶use Alien::Build::Util qw( _dump );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 5 our @EXPORT = qw( alien_ok run_ok xs_ok ffi_ok with_subtest synthetic helper_ok interpolate_template_is interpolate_run_ok plugin_ok );
19  
20 # ABSTRACT: Testing tools for Alien modules
21 5 our $VERSION = '2.88'; # VERSION
22  
23  
24 5 our @aliens;
25  
26 sub alien_ok ($;$)
27 15 ▶{
Subroutine alien_ok: called CC=12 SCAR=25.3
Pod documented
28 16 my($alien, $message) = @_;
29  
30 15 ▶ my $name = ref $alien ? ref($alien) . '[instance]' : $alien;
Branch: 1 branch
BranchTrueFalseTotal
ref $alien ? : 7 8 15
31 15 ▶ $name = 'undef' unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 1 14 15
32 15 my @methods = qw( cflags libs dynamic_libs bin_dir );
33 15 ▶ $message ||= "$name responds to: @methods";
Condition50%1/2
$message ||= "$name responds to: @methods"
l!l
015
MC/DC0%0/1
$message ||= "$name responds to: @methods"
$message
Truth table50%1/2
A
A= $message
Aresult
11
00
34  
35 15 my $ok;
36 my @diag;
37  
38 15 ▶ if(defined $alien)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $alien) { } 14 1 15
39 {
40 14 my @missing = grep { ! $alien->can($_) } @methods;
41  
42 14 $ok = !@missing;
43 14 push @diag, map { " missing method $_" } @missing;
44  
45 14 ▶ if($ok)
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) 13 1 14
46 {
47 13 push @aliens, $alien;
48 13 ▶ if($^O eq 'MSWin32' && $alien->isa('Alien::MSYS'))
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32' and $alien->isa('Alien::MSYS')) { } 0 13 13
Condition33%1/3
$^O eq "MSWin32" and $alien->isa("Alien::MSYS")
!ll&&!rl&&r
1300
MC/DC0%0/2
$^O eq "MSWin32" and $alien->isa("Alien::MSYS")
$^O eq "MSWin32" $alien->isa("Alien::MSYS")
Truth table33%1/3
A and B
A= $^O eq "MSWin32"B= $alien->isa("Alien::MSYS")
ABresult
0X0
100
111
49 {
50 0 unshift @PATH, Alien::MSYS::msys_path();
51 }
52 else
53 {
54 13 unshift @PATH, $alien->bin_dir;
55 }
56 }
57  
58 14 ▶ if($alien->can('alien_helper'))
Branch: 1 branch
BranchTrueFalseTotal
if ($alien->can("alien_helper")) 5 9 14
59 {
60 5 my($intr) = _interpolator();
61  
62 5 my $help = eval { $alien->alien_helper };
63  
64 5 ▶ if(my $error = $@)
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 0 5 5
65 {
66 0 $ok = 0;
67 0 push @diag, " error getting helpers: $error";
68 }
69  
70 5 foreach my $name (keys %$help)
71 {
72 5 my $code = $help->{$name};
73 5 $intr->replace_helper($name, $code);
74 }
75 }
76 }
77 else
78 {
79 1 $ok = 0;
80 1 push @diag, " undefined alien";
81 }
82  
83 15 my $ctx = context();
84 15 $ctx->ok($ok, $message);
85 15 $ctx->diag($_) for @diag;
86 15 $ctx->release;
87  
88 15 $ok;
89 }
90  
91  
92 sub synthetic
93 12 ▶{
Subroutine synthetic: called CC=2 SCAR=6.9
Pod documented
94 12 my($opt) = @_;
95 12 ▶ $opt ||= {};
Condition100%2/2
$opt ||= {}
l!l
111
MC/DC100%1/1
$opt ||= {}
$opt
Truth table100%2/2
A
A= $opt
Aresult
11
00
96 12 my %alien = %$opt;
97 12 require Test::Alien::Synthetic;
98 12 bless \%alien, 'Test::Alien::Synthetic',
99 }
100  
101  
102 sub run_ok
103 15 ▶{
Subroutine run_ok: called CC=13 SCAR=25.7
Pod documented
104 15 my($command, $message) = @_;
105  
106 15 ▶ my(@command) = ref $command ? @$command : (do {
Branch: 1 branch
BranchTrueFalseTotal
ref $command ? : 13 2 15
107 2 my $command = $command; # make a copy
108  
109 # Double the backslashes so that when they are unescaped by shellwords(),
110 # they become a single backslash. This should be fine on Windows since
111 # backslashes are not used to escape metacharacters in cmd.exe.
112 2 ▶ $command =~ s/\\/\\\\/g if $^O eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" 0 2 2
113 2 shellwords $command;
114 });
115 15 ▶ $message ||= ref $command ? "run @command" : "run $command";
Branch: 1 branch
BranchTrueFalseTotal
ref $command ? : 10 2 12
Condition66%2/3
$message ||= ref $command ? "run @command" : "run $command"
l!l&&r!l&&!r
3120
MC/DC0%0/2
$message ||= ref $command ? "run @command" : "run $command"
$message ref $command ? "run @command" : "run $command"
Truth table66%2/3
A ||= B
A= $messageB= ref $command ? "run @command" : "run $command"
ABresult
1X1
011
000
116  
117 15 require Test::Alien::Run;
118 15 my $run = bless {
119 out => '',
120 err => '',
121 exit => 0,
122 sig => 0,
123 cmd => [@command],
124 }, 'Test::Alien::Run';
125  
126 15 my $ctx = context();
127 15 my $exe = which $command[0];
128 15 ▶ if(defined $exe)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $exe) { } 14 1 15
129 {
130 14 ▶ if(ref $command)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $command) { } 12 2 14
131 {
132 12 shift @command;
133 12 $run->{cmd} = [$exe, @command];
134 }
135 else
136 {
137 2 $run->{cmd} = [$command];
138 }
139 14 my @diag;
140 14 my $ok = 1;
141 14 my($exit, $errno);
142 14 ▶ ($run->{out}, $run->{err}, $exit, $errno) = capture {
Subroutine __ANON__: called CC=2 SCAR=6.9
143  
144 14 ▶ if(ref $command)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $command) { } 12 2 14
145 {
146 12 system $exe, @command;
147 }
148 else
149 {
150 2 system $command;
151 }
152  
153 14 ($?,$!);
154 14 };
155  
156 14 ▶ if($exit == -1)
Branch: 2 branches
BranchTrueFalseTotal
if ($exit == -1) { } 1 13 14
elsif ($exit & 127) { } 1 12 13
157 {
158 1 $ok = 0;
159 1 $run->{fail} = "failed to execute: $errno";
160 1 push @diag, " failed to execute: $errno";
161 }
162 elsif($exit & 127)
163 {
164 1 $ok = 0;
165 1 push @diag, " killed with signal: @{[ $exit & 127 ]}";
166 1 $run->{sig} = $exit & 127;
167 }
168 else
169 {
170 12 $run->{exit} = $exit >> 8;
171 }
172  
173 14 $ctx->ok($ok, $message);
174 14 ▶ $ok
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 12 2 14
175 ? $ctx->note(" using $exe")
176 : $ctx->diag(" using $exe");
177 14 $ctx->diag(@diag) for @diag;
178  
179 }
180 else
181 {
182 1 $ctx->ok(0, $message);
183 1 $ctx->diag(" command not found");
184 1 $run->{fail} = 'command not found';
185 }
186  
187 15 ▶ unless(@aliens || $ENV{TEST_ALIEN_ALIENS_MISSING})
Branch: 1 branch
BranchTrueFalseTotal
unless (@Test::Alien::aliens or $ENV{"TEST_ALIEN_ALIENS_MISSING"}) 2 13 15
Condition66%2/3
@Test::Alien::aliens or $ENV{"TEST_ALIEN_ALIENS_MISSING"}
l!l&&r!l&&!r
1302
MC/DC50%1/2
@Test::Alien::aliens or $ENV{"TEST_ALIEN_ALIENS_MISSING"}
@Test::Alien::aliens $ENV{"TEST_ALIEN_ALIENS_MISSING"}
Truth table66%2/3
A or B
A= @Test::Alien::aliensB= $ENV{"TEST_ALIEN_ALIENS_MISSING"}
ABresult
1X1
011
000
188 {
189 2 $ctx->diag("run_ok called without any aliens, you may want to call alien_ok");
190 }
191  
192 15 $ctx->release;
193  
194 15 $run;
195 }
196  
197  
198 sub _flags
199 32 ▶{
Subroutine _flags: called CC=5 SCAR=16.6
200 32 my($class, $method) = @_;
201 32 my $static = "${method}_static";
202 32 ▶ $class->can($static) && $class->can('install_type') && $class->install_type eq 'share' && (!$class->can('xs_load'))
Branch: 1 branch
BranchTrueFalseTotal
$class->can($static) && $class->can('install_type') && $class->install_type eq 'share' && !$class->can('xs_load') ? : 9 23 32
Condition66%6/9
$class->can($static) and $class->can("install_type") and $class->install_type eq "share" and not $class->can("xs_load")
!ll&&!rl&&r
2309
$class->can($static) and $class->can("install_type") and $class->install_type eq "share"
!ll&&!rl&&r
2309
$class->can($static) and $class->can("install_type")
!ll&&!rl&&r
0239
MC/DC25%1/4
$class->can($static) and $class->can("install_type") and $class->install_type eq "share" and not $class->can("xs_load")
$class->can($static) $class->can("install_type") $class->install_type eq "share" not $class->can("xs_load")
Truth table40%2/5
A and B and C and not(D)
A= $class->can($static)B= $class->can("install_type")C= $class->install_type eq "share"D= not $class->can("xs_load")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
203 ? $class->$static
204 : $class->$method;
205 }
206  
207 sub xs_ok
208 16 ▶{
Subroutine xs_ok: called CC=66 SCAR=45.2
Pod documented
209 16 my $cb;
210 16 ▶ $cb = pop if defined $_[-1] && ref $_[-1] eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[-1] and ref $_[-1] eq "CODE" 10 6 16
Condition66%2/3
defined $_[-1] and ref $_[-1] eq "CODE"
!ll&&!rl&&r
0610
MC/DC50%1/2
defined $_[-1] and ref $_[-1] eq "CODE"
defined $_[-1] ref $_[-1] eq "CODE"
Truth table66%2/3
A and B
A= defined $_[-1]B= ref $_[-1] eq "CODE"
ABresult
0X0
100
111
211 16 my($xs, $message) = @_;
212 16 ▶ $message ||= 'xs';
Condition100%2/2
$message ||= "xs"
l!l
313
MC/DC100%1/1
$message ||= "xs"
$message
Truth table100%2/2
A
A= $message
Aresult
11
00
213  
214 16 ▶ $xs = { xs => $xs } unless ref $xs;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $xs 8 8 16
215 # make sure this is a copy because we may
216 # modify it.
217 16 $xs->{xs} = "@{[ $xs->{xs} ]}";
218 16 ▶ $xs->{pxs} ||= {};
Condition50%1/2
$xs->{"pxs"} ||= {}
l!l
016
MC/DC0%0/1
$xs->{"pxs"} ||= {}
$xs->{"pxs"}
Truth table50%1/2
A
A= $xs->{"pxs"}
Aresult
11
00
219 16 ▶ $xs->{cbuilder_check} ||= 'have_compiler';
Condition50%1/2
$xs->{"cbuilder_check"} ||= "have_compiler"
l!l
016
MC/DC0%0/1
$xs->{"cbuilder_check"} ||= "have_compiler"
$xs->{"cbuilder_check"}
Truth table50%1/2
A
A= $xs->{"cbuilder_check"}
Aresult
11
00
220 16 ▶ $xs->{cbuilder_config} ||= {};
Condition100%2/2
$xs->{"cbuilder_config"} ||= {}
l!l
115
MC/DC100%1/1
$xs->{"cbuilder_config"} ||= {}
$xs->{"cbuilder_config"}
Truth table100%2/2
A
A= $xs->{"cbuilder_config"}
Aresult
11
00
221 16 ▶ $xs->{cbuilder_compile} ||= {};
Condition100%2/2
$xs->{"cbuilder_compile"} ||= {}
l!l
214
MC/DC100%1/1
$xs->{"cbuilder_compile"} ||= {}
$xs->{"cbuilder_compile"}
Truth table100%2/2
A
A= $xs->{"cbuilder_compile"}
Aresult
11
00
222 16 ▶ $xs->{cbuilder_link} ||= {};
Condition50%1/2
$xs->{"cbuilder_link"} ||= {}
l!l
016
MC/DC0%0/1
$xs->{"cbuilder_link"} ||= {}
$xs->{"cbuilder_link"}
Truth table50%1/2
A
A= $xs->{"cbuilder_link"}
Aresult
11
00
223  
224 16 require ExtUtils::CBuilder;
225 16 my $skip = do {
226 16 my $have_compiler = $xs->{cbuilder_check};
227 16 my %config = %{ $xs->{cbuilder_config} };
228 16 !ExtUtils::CBuilder->new( config => \%config )->$have_compiler;
229 };
230  
231 16 ▶ if($skip)
Branch: 1 branch
BranchTrueFalseTotal
if ($skip) 4 12 16
232 {
233 4 my $ctx = context();
234 4 $ctx->skip($message, 'test requires a compiler');
235 4 ▶ $ctx->skip("$message subtest", 'test requires a compiler') if $cb;
Branch: 1 branch
BranchTrueFalseTotal
if $cb 2 2 4
236 4 $ctx->release;
237 4 return;
238 }
239  
240 12 ▶ if($xs->{cpp} || $xs->{'C++'})
Branch: 1 branch
BranchTrueFalseTotal
if ($xs->{'cpp'} or $xs->{'C++'}) { } 0 12 12
Condition33%1/3
$xs->{"cpp"} or $xs->{"C++"}
l!l&&r!l&&!r
0012
MC/DC0%0/2
$xs->{"cpp"} or $xs->{"C++"}
$xs->{"cpp"} $xs->{"C++"}
Truth table33%1/3
A or B
A= $xs->{"cpp"}B= $xs->{"C++"}
ABresult
1X1
011
000
241 {
242 0 my $ctx = context();
243 0 $ctx->bail("The cpp and C++ options have been removed from xs_ok");
244 }
245 else
246 {
247 12 ▶ $xs->{c_ext} ||= 'c';
Condition50%1/2
$xs->{"c_ext"} ||= "c"
l!l
012
MC/DC0%0/1
$xs->{"c_ext"} ||= "c"
$xs->{"c_ext"}
Truth table50%1/2
A
A= $xs->{"c_ext"}
Aresult
11
00
248 }
249  
250 12 ▶ my $verbose = $xs->{verbose} || 0;
Condition100%2/2
$xs->{'verbose'} || 0
l!l
66
MC/DC100%1/1
$xs->{'verbose'} || 0
$xs->{'verbose'}
Truth table100%2/2
A
A= $xs->{'verbose'}
Aresult
11
00
251 12 my $ok = 1;
252 12 my @diag;
253 12 ▶ my $dir = Alien::Build::Temp->newdir(
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /^(MSWin32|cygwin|msys)$/ ? : 0 12 12
254 TEMPLATE => 'test-alien-XXXXXX',
255 CLEANUP => $^O =~ /^(MSWin32|cygwin|msys)$/ ? 0 : 1,
256 );
257  
258 12 my $xs_filename = path($dir)->child('test.xs')->stringify;
259 12 my $c_filename = path($dir)->child("test.@{[ $xs->{c_ext} ]}")->stringify;
260  
261 12 my $ctx = context();
262 12 my $module;
263  
264 12 ▶ if($ENV{TEST_ALIEN_ALWAYS_KEEP})
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"TEST_ALIEN_ALWAYS_KEEP"}) 0 12 12
265 {
266 0 $dir->unlink_on_destroy(0);
267 0 $ctx->note("keeping XS temporary directory $dir at user request");
268 }
269  
270 12 ▶ if($xs->{xs} =~ /\bTA_MODULE\b/)
Branch: 1 branch
BranchTrueFalseTotal
if ($xs->{"xs"} =~ /\bTA_MODULE\b/) 8 4 12
271 {
272 8 our $count;
273 8 ▶ $count = 0 unless defined $count;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Test::Alien::count 2 6 8
274 8 my $name = sprintf "Test::Alien::XS::Mod%s%s", $count, chr(65 + $count % 26 ) x 4;
275 8 $count++;
276 8 my $code = $xs->{xs};
277 8 $code =~ s{\bTA_MODULE\b}{$name}g;
278 8 $xs->{xs} = $code;
279 }
280  
281 # this regex copied shamefully from ExtUtils::ParseXS
282 # in part because we need the module name to do the bootstrap
283 # and also because if this regex doesn't match then ParseXS
284 # does an exit() which we don't want.
285 12 ▶ if($xs->{xs} =~ /^MODULE\s*=\s*([\w:]+)(?:\s+PACKAGE\s*=\s*([\w:]+))?(?:\s+PREFIX\s*=\s*(\S+))?\s*$/m)
Branch: 1 branch
BranchTrueFalseTotal
if ($xs->{'xs'} =~ /^MODULE\s*=\s*([\w:]+)(?:\s+PACKAGE\s*=\s*([\w:]+))?(?:\s+PREFIX\s*=\s*(\S+))?\s*$/m) { } 10 2 12
286 {
287 10 $module = $1;
288 10 ▶ $ctx->note("detect module name $module") if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 6 4 10
289 }
290 else
291 {
292 2 $ok = 0;
293 2 push @diag, ' XS does not have a module decleration that we could find';
294 }
295  
296 12 ▶ if($ok)
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) 10 2 12
297 {
298 10 open my $fh, '>', $xs_filename;
299 10 print $fh $xs->{xs};
300 10 close $fh;
301  
302 10 require ExtUtils::ParseXS;
303 10 my $pxs = ExtUtils::ParseXS->new;
304  
305 10 ▶ my($out, $err) = capture_merged {
Subroutine __ANON__: called CC=1 SCAR=0.0
306 10 eval {
307 $pxs->process_file(
308 filename => $xs_filename,
309 output => $c_filename,
310 versioncheck => 0,
311 prototypes => 0,
312 10 %{ $xs->{pxs} },
313 );
314 };
315 10 $@;
316 10 };
317  
318 10 ▶ $ctx->note("parse xs $xs_filename => $c_filename") if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 6 4 10
319 10 ▶ $ctx->note($out) if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 6 4 10
320 10 ▶ $ctx->note("error: $err") if $verbose && $err;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose and $err 0 10 10
Condition66%2/3
$verbose and $err
!ll&&!rl&&r
460
MC/DC0%0/2
$verbose and $err
$verbose $err
Truth table66%2/3
A and B
A= $verboseB= $err
ABresult
0X0
100
111
321  
322 10 ▶ unless($pxs->report_error_count == 0)
Branch: 1 branch
BranchTrueFalseTotal
unless ($pxs->report_error_count == 0) 0 10 10
323 {
324 0 $ok = 0;
325 0 push @diag, ' ExtUtils::ParseXS failed:';
326 0 ▶ push @diag, " $err" if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
327 0 push @diag, " $_" for split /\r?\n/, $out;
328 }
329 }
330  
331 12 ▶ push @diag, "xs_ok called without any aliens, you may want to call alien_ok" unless @aliens || $ENV{TEST_ALIEN_ALIENS_MISSING};
Branch: 1 branch
BranchTrueFalseTotal
unless @Test::Alien::aliens or $ENV{"TEST_ALIEN_ALIENS_MISSING"} 1 11 12
Condition66%2/3
@Test::Alien::aliens or $ENV{"TEST_ALIEN_ALIENS_MISSING"}
l!l&&r!l&&!r
1101
MC/DC50%1/2
@Test::Alien::aliens or $ENV{"TEST_ALIEN_ALIENS_MISSING"}
@Test::Alien::aliens $ENV{"TEST_ALIEN_ALIENS_MISSING"}
Truth table66%2/3
A or B
A= @Test::Alien::aliensB= $ENV{"TEST_ALIEN_ALIENS_MISSING"}
ABresult
1X1
011
000
332  
333 12 ▶ if($ok)
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) 10 2 12
334 {
335 my $cb = ExtUtils::CBuilder->new(
336 10 config => do {
337 10 my %config = %{ $xs->{cbuilder_config} };
338 10 my $lddlflags = join(' ', grep !/^-l/, shellwords map { _flags $_, 'libs' } @aliens) . " $Config{lddlflags}";
339 10 ▶ $config{lddlflags} = defined $config{lddlflags} ? "$lddlflags $config{lddlflags}" : $lddlflags;
Branch: 1 branch
BranchTrueFalseTotal
defined $config{'lddlflags'} ? : 0 10 10
340 10 \%config;
341 },
342 );
343  
344 my %compile_options = (
345 source => $c_filename,
346 10 %{ $xs->{cbuilder_compile} },
347 );
348  
349 10 ▶ if(defined $compile_options{extra_compiler_flags} && ref($compile_options{extra_compiler_flags}) eq '')
Branch: 1 branch
BranchTrueFalseTotal
if (defined $compile_options{"extra_compiler_flags"} and ref $compile_options{"extra_compiler_flags"} eq "") 1 9 10
Condition100%3/3
defined $compile_options{"extra_compiler_flags"} and ref $compile_options{"extra_compiler_flags"} eq ""
!ll&&!rl&&r
811
MC/DC100%2/2
defined $compile_options{"extra_compiler_flags"} and ref $compile_options{"extra_compiler_flags"} eq ""
defined $compile_options{"extra_compiler_flags"} ref $compile_options{"extra_compiler_flags"} eq ""
Truth table100%3/3
A and B
A= defined $compile_options{"extra_compiler_flags"}B= ref $compile_options{"extra_compiler_flags"} eq ""
ABresult
0X0
100
111
350 {
351 1 $compile_options{extra_compiler_flags} = [ shellwords $compile_options{extra_compiler_flags} ];
352 }
353  
354 10 push @{ $compile_options{extra_compiler_flags} }, shellwords map { _flags $_, 'cflags' } @aliens;
355  
356 10 ▶ my($out, $obj, $err) = capture_merged {
Subroutine __ANON__: called CC=1 SCAR=0.0
357 10 my $obj = eval {
358 10 $cb->compile(%compile_options);
359 };
360 10 ($obj, $@);
361 10 };
362  
363 10 ▶ $ctx->note("compile $c_filename") if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 6 4 10
364 10 ▶ $ctx->note($out) if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 6 4 10
365 10 ▶ $ctx->note($err) if $verbose && $err;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose and $err 0 10 10
Condition66%2/3
$verbose and $err
!ll&&!rl&&r
460
MC/DC0%0/2
$verbose and $err
$verbose $err
Truth table66%2/3
A and B
A= $verboseB= $err
ABresult
0X0
100
111
366  
367 10 ▶ if($verbose > 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1) 0 10 10
368 {
369 0 $ctx->note(_dump({ compile_options => \%compile_options }));
370 }
371  
372 10 ▶ unless($obj)
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj) 1 9 10
373 {
374 1 $ok = 0;
375 1 push @diag, ' ExtUtils::CBuilder->compile failed';
376 1 ▶ push @diag, " $err" if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 1 0 1
377 1 push @diag, " $_" for split /\r?\n/, $out;
378 }
379  
380 10 ▶ if($ok)
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) 9 1 10
381 {
382  
383 my %link_options = (
384 objects => [$obj],
385 module_name => $module,
386 9 %{ $xs->{cbuilder_link} },
387 );
388  
389 9 ▶ if(defined $link_options{extra_linker_flags} && ref($link_options{extra_linker_flags}) eq '')
Branch: 1 branch
BranchTrueFalseTotal
if (defined $link_options{"extra_linker_flags"} and ref $link_options{"extra_linker_flags"} eq "") 0 9 9
Condition33%1/3
defined $link_options{"extra_linker_flags"} and ref $link_options{"extra_linker_flags"} eq ""
!ll&&!rl&&r
900
MC/DC0%0/2
defined $link_options{"extra_linker_flags"} and ref $link_options{"extra_linker_flags"} eq ""
defined $link_options{"extra_linker_flags"} ref $link_options{"extra_linker_flags"} eq ""
Truth table33%1/3
A and B
A= defined $link_options{"extra_linker_flags"}B= ref $link_options{"extra_linker_flags"} eq ""
ABresult
0X0
100
111
390 {
391 0 $link_options{extra_linker_flags} = [ shellwords $link_options{extra_linker_flags} ];
392 }
393  
394 9 unshift @{ $link_options{extra_linker_flags} }, grep /^-l/, shellwords map { _flags $_, 'libs' } @aliens;
395  
396 9 ▶ my($out, $lib, $err) = capture_merged {
Subroutine __ANON__: called CC=1 SCAR=0.0
397 9 my $lib = eval {
398 9 $cb->link(%link_options);
399 };
400 9 ($lib, $@);
401 9 };
402  
403 9 ▶ $ctx->note("link $obj") if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 6 3 9
404 9 ▶ $ctx->note($out) if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 6 3 9
405 9 ▶ $ctx->note($err) if $verbose && $err;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose and $err 0 9 9
Condition66%2/3
$verbose and $err
!ll&&!rl&&r
360
MC/DC0%0/2
$verbose and $err
$verbose $err
Truth table66%2/3
A and B
A= $verboseB= $err
ABresult
0X0
100
111
406  
407 9 ▶ if($verbose > 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1) 0 9 9
408 {
409 0 $ctx->note(_dump({ link_options => \%link_options }));
410 }
411  
412 9 ▶ if($lib && -f $lib)
Branch: 1 branch
BranchTrueFalseTotal
if ($lib and -f $lib) { } 9 0 9
Condition33%1/3
$lib and -f $lib
!ll&&!rl&&r
009
MC/DC0%0/2
$lib and -f $lib
$lib -f $lib
Truth table33%1/3
A and B
A= $libB= -f $lib
ABresult
0X0
100
111
413 {
414 9 ▶ $ctx->note("created lib $lib") if $xs->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $xs->{"verbose"} 6 3 9
415 }
416 else
417 {
418 0 $ok = 0;
419 0 push @diag, ' ExtUtils::CBuilder->link failed';
420 0 ▶ push @diag, " $err" if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
421 0 push @diag, " $_" for split /\r?\n/, $out;
422 }
423  
424 9 ▶ if($ok)
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) 9 0 9
425 {
426 9 my @modparts = split(/::/,$module);
427 9 my $dl_dlext = $Config{dlext};
428 9 my $modfname = $modparts[-1];
429  
430 9 my $libpath = path($dir)->child('auto', @modparts, "$modfname.$dl_dlext");
431 9 $libpath->parent->mkpath;
432 9 ▶ move($lib, "$libpath") || die "unable to copy $lib => $libpath $!";
Branch: 1 branch
BranchTrueFalseTotal
move($lib, "$libpath") or die "unable to copy $lib => $libpath $!" 9 0 9
433  
434 9 pop @modparts;
435 9 my $pmpath = path($dir)->child(@modparts, "$modfname.pm");
436 9 $pmpath->parent->mkpath;
437 9 open my $fh, '>', "$pmpath";
438  
439 9 my($alien_with_xs_load, @rest) = grep { $_->can('xs_load') } @aliens;
440  
441 9 ▶ if($alien_with_xs_load)
Branch: 1 branch
BranchTrueFalseTotal
if ($alien_with_xs_load) { } 1 8 9
442 {
443 {
444 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
445 1 @{join '::', $module, 'rest'} = @rest;
446 1 ${join '::', $module, 'alien_with_xs_load'} = $alien_with_xs_load;
447 }
448 1 print $fh '# line '. __LINE__ . ' "' . __FILE__ . qq("\n) . qq{
449 package $module;
450  
451 use strict;
452 use warnings;
453 our \$VERSION = '0.01';
454 our \@rest;
455 our \$alien_with_xs_load;
456  
457 \$alien_with_xs_load->xs_load('$module', \$VERSION, \@rest);
458  
459 1;
460 };
461 }
462 else
463 {
464 8 print $fh '# line '. __LINE__ . ' "' . __FILE__ . qq("\n) . qq{
465 package $module;
466  
467 2 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
468 2 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
469 require XSLoader;
470 our \$VERSION = '0.01';
471 XSLoader::load('$module',\$VERSION);
472  
473 1;
474 };
475 }
476 9 close $fh;
477  
478 {
479 9 local @INC = @INC;
480 9 unshift @INC, "$dir";
481 ## no critic
482 9 eval '# line '. __LINE__ . ' "' . __FILE__ . qq("\n) . qq{
483 2 ▶ use $module;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
484 };
485 ## use critic
486 }
487  
488 9 ▶ if(my $error = $@)
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 0 9 9
489 {
490 0 $ok = 0;
491 0 push @diag, ' XSLoader failed';
492 0 push @diag, " $error";
493 }
494 }
495 }
496 }
497  
498 12 $ctx->ok($ok, $message);
499 12 $ctx->diag($_) for @diag;
500 12 $ctx->release;
501  
502 12 ▶ unless($ok || defined $ENV{TEST_ALIEN_ALWAYS_KEEP})
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok or defined $ENV{"TEST_ALIEN_ALWAYS_KEEP"}) 0 12 12
Condition66%2/3
$ok or defined $ENV{"TEST_ALIEN_ALWAYS_KEEP"}
l!l&&r!l&&!r
930
MC/DC0%0/2
$ok or defined $ENV{"TEST_ALIEN_ALWAYS_KEEP"}
$ok defined $ENV{"TEST_ALIEN_ALWAYS_KEEP"}
Truth table66%2/3
A or B
A= $okB= defined $ENV{"TEST_ALIEN_ALWAYS_KEEP"}
ABresult
1X1
011
000
503 {
504 0 $ctx->note("keeping XS temporary directory $dir due to failure");
505 0 $dir->unlink_on_destroy(0);
506 }
507  
508 12 ▶ if($cb)
Branch: 1 branch
BranchTrueFalseTotal
if ($cb) 8 4 12
509 {
510 1 ▶ $cb = sub {
Subroutine __ANON__: called CC=1 SCAR=0.4
511 1 my $ctx = context();
512 1 $ctx->plan(0, 'SKIP', "subtest requires xs success");
513 0 $ctx->release;
514 8 ▶ } unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 7 8
515  
516 8 @_ = ("$message subtest", $cb, 1, $module);
517  
518 8 goto \&Test2::API::run_subtest;
519 }
520  
521 4 $ok;
522 }
523  
524 sub with_subtest (&)
525 8 ▶{
Subroutine with_subtest: called CC=2 SCAR=7.0
Pod undocumented
526 8 my($code) = @_;
527  
528 # it may be possible to catch a segmentation fault,
529 # but not with signal handlers apparently. See:
530 # https://feepingcreature.github.io/handling.html
531 8 ▶ return $code if $^O eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" 0 8 8
532  
533 # try to catch a segmentation fault and bail out
534 # with a useful diagnostic. prove test to swallow
535 # the diagnostic on such failures.
536 8 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
537 1 ▶ local $SIG{SEGV} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
538 1 my $ctx = context();
539 1 $ctx->bail("Segmentation fault");
540 8 };
541 8 $code->(@_);
542 }
543 8 }
544  
545  
546 sub ffi_ok
547 0 ▶{
Subroutine ffi_ok: not called CC=23 SCAR=63.1
Pod documented
548 0 my $cb;
549 0 ▶ $cb = pop if defined $_[-1] && ref $_[-1] eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[-1] and ref $_[-1] eq "CODE" 0 0 0
Condition0%0/3
defined $_[-1] and ref $_[-1] eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[-1] and ref $_[-1] eq "CODE"
defined $_[-1] ref $_[-1] eq "CODE"
Truth table0%0/3
A and B
A= defined $_[-1]B= ref $_[-1] eq "CODE"
ABresult
0X0
100
111
550 0 my($opt, $message) = @_;
551  
552 0 ▶ $message ||= 'ffi';
Condition0%0/2
$message ||= "ffi"
l!l
00
MC/DC0%0/1
$message ||= "ffi"
$message
Truth table0%0/2
A
A= $message
Aresult
11
00
553  
554 0 my $ok = 1;
555 0 my $skip;
556 my $ffi;
557 0 my @diag;
558  
559 {
560 0 my $min = '0.12'; # the first CPAN release
561 0 ▶ $min = '0.15' if $opt->{ignore_not_found};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"ignore_not_found"} 0 0 0
562 0 ▶ $min = '0.18' if $opt->{lang};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"lang"} 0 0 0
563 0 ▶ $min = '0.99' if defined $opt->{api} && $opt->{api} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt->{"api"} and $opt->{"api"} > 0 0 0 0
Condition0%0/3
defined $opt->{"api"} and $opt->{"api"} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $opt->{"api"} and $opt->{"api"} > 0
defined $opt->{"api"} $opt->{"api"} > 0
Truth table0%0/3
A and B
A= defined $opt->{"api"}B= $opt->{"api"} > 0
ABresult
0X0
100
111
564 0 ▶ unless(eval { require FFI::Platypus; FFI::Platypus->VERSION($min) })
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require FFI::Platypus; "FFI::Platypus"->VERSION($min) } }) 0 0 0
565 {
566 0 $ok = 0;
567 0 $skip = "Test requires FFI::Platypus $min";
568 }
569 }
570  
571 0 ▶ if($ok && $opt->{lang})
Branch: 1 branch
BranchTrueFalseTotal
if ($ok and $opt->{"lang"}) 0 0 0
Condition0%0/3
$ok and $opt->{"lang"}
!ll&&!rl&&r
000
MC/DC0%0/2
$ok and $opt->{"lang"}
$ok $opt->{"lang"}
Truth table0%0/3
A and B
A= $okB= $opt->{"lang"}
ABresult
0X0
100
111
572 {
573 0 my $class = "FFI::Platypus::Lang::@{[ $opt->{lang} ]}";
574 {
575 0 my $pm = "$class.pm";
576 0 $pm =~ s/::/\//g;
577 0 eval { require $pm };
578 }
579 0 ▶ if($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
580 {
581 0 $ok = 0;
582 0 $skip = "Test requires FFI::Platypus::Lang::@{[ $opt->{lang} ]}";
583 }
584 }
585  
586 0 ▶ unless(@aliens || $ENV{TEST_ALIEN_ALIENS_MISSING})
Branch: 1 branch
BranchTrueFalseTotal
unless (@Test::Alien::aliens or $ENV{"TEST_ALIEN_ALIENS_MISSING"}) 0 0 0
Condition0%0/3
@Test::Alien::aliens or $ENV{"TEST_ALIEN_ALIENS_MISSING"}
l!l&&r!l&&!r
000
MC/DC0%0/2
@Test::Alien::aliens or $ENV{"TEST_ALIEN_ALIENS_MISSING"}
@Test::Alien::aliens $ENV{"TEST_ALIEN_ALIENS_MISSING"}
Truth table0%0/3
A or B
A= @Test::Alien::aliensB= $ENV{"TEST_ALIEN_ALIENS_MISSING"}
ABresult
1X1
011
000
587 {
588 0 push @diag, 'ffi_ok called without any aliens, you may want to call alien_ok';
589 }
590  
591 0 ▶ if($ok)
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) 0 0 0
592 {
593 $ffi = FFI::Platypus->new(
594 0 do {
595 my @args = (
596 0 lib => [map { $_->dynamic_libs } @aliens],
597 ignore_not_found => $opt->{ignore_not_found},
598 lang => $opt->{lang},
599 0 );
600 0 ▶ push @args, api => $opt->{api} if defined $opt->{api};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt->{"api"} 0 0 0
601 0 @args;
602 }
603 );
604 0 ▶ foreach my $symbol (@{ $opt->{symbols} || [] })
Condition0%0/2
$opt->{'symbols'} || []
l!l
00
MC/DC0%0/1
$opt->{'symbols'} || []
$opt->{'symbols'}
Truth table0%0/2
A
A= $opt->{'symbols'}
Aresult
11
00
605 {
606 0 ▶ unless($ffi->find_symbol($symbol))
Branch: 1 branch
BranchTrueFalseTotal
unless ($ffi->find_symbol($symbol)) 0 0 0
607 {
608 0 $ok = 0;
609 0 push @diag, " $symbol not found"
610 }
611 }
612 }
613  
614 0 my $ctx = context();
615  
616 0 ▶ if($skip)
Branch: 1 branch
BranchTrueFalseTotal
if ($skip) { } 0 0 0
617 {
618 0 $ctx->skip($message, $skip);
619 }
620 else
621 {
622 0 $ctx->ok($ok, $message);
623 }
624 0 $ctx->diag($_) for @diag;
625  
626 0 $ctx->release;
627  
628 0 ▶ if($cb)
Branch: 1 branch
BranchTrueFalseTotal
if ($cb) 0 0 0
629 {
630 0 ▶ $cb = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
631 0 my $ctx = context();
632 0 $ctx->plan(0, 'SKIP', "subtest requires ffi success");
633 0 $ctx->release;
634 0 ▶ } unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
635  
636 0 @_ = ("$message subtest", $cb, 1, $ffi);
637  
638 0 goto \&Test2::API::run_subtest;
639 }
640  
641 0 $ok;
642 }
643  
644  
645 {
646 3 my @ret;
647  
648 sub _interpolator
649 25 ▶ {
Subroutine _interpolator: called CC=2 SCAR=6.9
650 25 ▶ return @ret if @ret;
Branch: 1 branch
BranchTrueFalseTotal
if @ret 23 2 25
651  
652 2 require Alien::Build::Interpolate::Default;
653 2 my $intr = Alien::Build::Interpolate::Default->new;
654  
655 2 require Alien::Build;
656 2 my $build = Alien::Build->new;
657 2 $build->meta->interpolator($intr);
658  
659 2 @ret = ($intr, $build);
660 }
661 }
662  
663 sub helper_ok
664 5 ▶{
Subroutine helper_ok: called CC=4 SCAR=13.9
Pod documented
665 7 my($name, $message) = @_;
666  
667 7 ▶ $message ||= "helper $name exists";
Condition100%2/2
$message ||= "helper $name exists"
l!l
25
MC/DC100%1/1
$message ||= "helper $name exists"
$message
Truth table100%2/2
A
A= $message
Aresult
11
00
668  
669 7 my($intr) = _interpolator;
670  
671 7 my $code = $intr->has_helper($name);
672  
673 7 my $ok = defined $code;
674  
675 7 my $ctx = context();
676 7 $ctx->ok($ok, $message);
677 7 ▶ $ctx->diag("helper_ok called without any aliens, you may want to call alien_ok") unless @aliens || $ENV{TEST_ALIEN_ALIENS_MISSING};
Branch: 1 branch
BranchTrueFalseTotal
unless @Test::Alien::aliens or $ENV{"TEST_ALIEN_ALIENS_MISSING"} 1 6 7
Condition100%3/3
@Test::Alien::aliens or $ENV{"TEST_ALIEN_ALIENS_MISSING"}
l!l&&r!l&&!r
511
MC/DC100%2/2
@Test::Alien::aliens or $ENV{"TEST_ALIEN_ALIENS_MISSING"}
@Test::Alien::aliens $ENV{"TEST_ALIEN_ALIENS_MISSING"}
Truth table100%3/3
A or B
A= @Test::Alien::aliensB= $ENV{"TEST_ALIEN_ALIENS_MISSING"}
ABresult
1X1
011
000
678 7 $ctx->release;
679  
680 7 $ok;
681 }
682  
683  
684 sub plugin_ok
685 1 ▶{
Subroutine plugin_ok: called CC=9 SCAR=26.9
Pod documented
686 1 my($name, $message) = @_;
687  
688 1 my @args;
689  
690 1 ▶ ($name, @args) = @$name if ref $name;
Branch: 1 branch
BranchTrueFalseTotal
if ref $name 0 1 1
691  
692 1 ▶ $message ||= "plugin $name";
Condition50%1/2
$message ||= "plugin $name"
l!l
01
MC/DC0%0/1
$message ||= "plugin $name"
$message
Truth table50%1/2
A
A= $message
Aresult
11
00
693  
694 1 my($intr, $build) = _interpolator;
695  
696 1 my $class = "Alien::Build::Plugin::$name";
697 1 my $pm = "$class.pm";
698 1 $pm =~ s/::/\//g;
699  
700 1 my $ctx = context();
701  
702 1 my $plugin = eval {
703 1 ▶ require $pm unless $class->can('new');
Branch: 1 branch
BranchTrueFalseTotal
unless $class->can("new") 1 0 1
704 1 $class->new(@args);
705 };
706  
707 1 ▶ if(my $error = $@)
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 0 1 1
708 {
709 0 $ctx->ok(0, $message, ['unable to create $name plugin', $error]);
710 0 $ctx->release;
711 0 return 0;
712 }
713  
714 1 eval {
715 1 $plugin->init($build->meta);
716 };
717  
718 1 ▶ if($^O eq 'MSWin32' && ($plugin->isa('Alien::Build::Plugin::Build::MSYS') || $plugin->isa('Alien::Build::Plugin::Build::Autoconf')))
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32" and $plugin->isa("Alien::Build::Plugin::Build::MSYS") || $plugin->isa("Alien::Build::Plugin::Build::Autoconf")) 0 1 1
Condition16%1/6
$^O eq "MSWin32" and $plugin->isa("Alien::Build::Plugin::Build::MSYS") || $plugin->isa("Alien::Build::Plugin::Build::Autoconf")
!ll&&!rl&&r
100
$plugin->isa("Alien::Build::Plugin::Build::MSYS") or $plugin->isa("Alien::Build::Plugin::Build::Autoconf")
l!l&&r!l&&!r
000
MC/DC0%0/3
$^O eq "MSWin32" and $plugin->isa("Alien::Build::Plugin::Build::MSYS") || $plugin->isa("Alien::Build::Plugin::Build::Autoconf")
$^O eq "MSWin32" $plugin->isa("Alien::Build::Plugin::Build::MSYS") $plugin->isa("Alien::Build::Plugin::Build::Autoconf")
Truth table25%1/4
A and B or C
A= $^O eq "MSWin32"B= $plugin->isa("Alien::Build::Plugin::Build::MSYS")C= $plugin->isa("Alien::Build::Plugin::Build::Autoconf")
ABCresult
0XX0
1000
11X1
1011
719 {
720 0 require Alien::MSYS;
721 0 unshift @PATH, Alien::MSYS::msys_path();
722 }
723  
724 1 ▶ if(my $error = $@)
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) { } 0 1 1
725 {
726 0 $ctx->ok(0, $message, ['unable to initiate $name plugin', $error]);
727 0 $ctx->release;
728 0 return 0;
729 }
730 else
731 {
732 1 $ctx->ok(1, $message);
733 1 $ctx->release;
734 1 return 1;
735 }
736 }
737  
738  
739 sub interpolate_template_is
740 9 ▶{
Subroutine interpolate_template_is: called CC=8 SCAR=20.8
Pod documented
741 9 my($template, $pattern, $message) = @_;
742  
743 9 ▶ $message ||= "template matches";
Condition100%2/2
$message ||= "template matches"
l!l
18
MC/DC100%1/1
$message ||= "template matches"
$message
Truth table100%2/2
A
A= $message
Aresult
11
00
744  
745 9 my($intr) = _interpolator;
746  
747 9 my $value = eval { $intr->interpolate($template) };
748 9 my $error = $@;
749 9 my @diag;
750 my $ok;
751  
752 9 ▶ if($error)
Branch: 2 branches
BranchTrueFalseTotal
if ($error) { } 1 8 9
elsif (ref $pattern eq 'Regexp') { } 2 6 8
753 {
754 1 $ok = 0;
755 1 push @diag, "error in evaluation:";
756 1 push @diag, " $error";
757 }
758 elsif(ref($pattern) eq 'Regexp')
759 {
760 2 $ok = $value =~ $pattern;
761 2 ▶ push @diag, "value '$value' does not match $pattern'" unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 1 2
762 }
763 else
764 {
765 6 $ok = $value eq "$pattern";
766 6 ▶ push @diag, "value '$value' does not equal '$pattern'" unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 5 6
767 }
768  
769 9 my $ctx = context();
770 9 $ctx->ok($ok, $message, [@diag]);
771 9 ▶ $ctx->diag('interpolate_template_is called without any aliens, you may want to call alien_ok') unless @aliens || $ENV{TEST_ALIEN_ALIENS_MISSING};
Branch: 1 branch
BranchTrueFalseTotal
unless @Test::Alien::aliens or $ENV{"TEST_ALIEN_ALIENS_MISSING"} 1 8 9
Condition100%3/3
@Test::Alien::aliens or $ENV{"TEST_ALIEN_ALIENS_MISSING"}
l!l&&r!l&&!r
711
MC/DC100%2/2
@Test::Alien::aliens or $ENV{"TEST_ALIEN_ALIENS_MISSING"}
@Test::Alien::aliens $ENV{"TEST_ALIEN_ALIENS_MISSING"}
Truth table100%3/3
A or B
A= @Test::Alien::aliensB= $ENV{"TEST_ALIEN_ALIENS_MISSING"}
ABresult
1X1
011
000
772 9 $ctx->release;
773  
774 9 $ok;
775 }
776  
777  
778 sub interpolate_run_ok
779 3 ▶{
Subroutine interpolate_run_ok: called CC=9 SCAR=22.1
Pod documented
780 3 my($template, $message) = @_;
781  
782 3 ▶ my(@template) = ref $template ? @$template : ($template);
Branch: 1 branch
BranchTrueFalseTotal
ref $template ? : 1 2 3
783  
784 3 my($intr) = _interpolator;
785  
786 3 my $ok = 1;
787 3 my @diag;
788 my @command;
789  
790 3 foreach my $template (@template)
791 {
792 5 my $command = eval { $intr->interpolate($template) };
793 5 ▶ if(my $error = $@)
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) { } 1 4 5
794 {
795 1 $ok = 0;
796 1 push @diag, "error in evaluation:";
797 1 push @diag, " $error";
798 }
799 else
800 {
801 4 push @command, $command;
802 }
803 }
804  
805 3 my $ctx = context();
806  
807 3 ▶ if($ok)
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) { } 2 1 3
808 {
809 2 ▶ my $command = ref $template ? \@command : $command[0];
Branch: 1 branch
BranchTrueFalseTotal
ref $template ? : 1 1 2
810 2 $ok = run_ok($command, $message);
811 }
812 else
813 {
814 1 ▶ $message ||= "run @template";
Condition50%1/2
$message ||= "run @template"
l!l
01
MC/DC0%0/1
$message ||= "run @template"
$message
Truth table50%1/2
A
A= $message
Aresult
11
00
815 1 $ctx->ok($ok, $message, [@diag]);
816 1 ▶ $ctx->diag('interpolate_run_ok called without any aliens, you may want to call alien_ok') unless @aliens || $ENV{TEST_ALIEN_ALIENS_MISSING};
Branch: 1 branch
BranchTrueFalseTotal
unless @Test::Alien::aliens or $ENV{"TEST_ALIEN_ALIENS_MISSING"} 0 1 1
Condition33%1/3
@Test::Alien::aliens or $ENV{"TEST_ALIEN_ALIENS_MISSING"}
l!l&&r!l&&!r
100
MC/DC0%0/2
@Test::Alien::aliens or $ENV{"TEST_ALIEN_ALIENS_MISSING"}
@Test::Alien::aliens $ENV{"TEST_ALIEN_ALIENS_MISSING"}
Truth table33%1/3
A or B
A= @Test::Alien::aliensB= $ENV{"TEST_ALIEN_ALIENS_MISSING"}
ABresult
1X1
011
000
817 }
818  
819 3 $ctx->release;
820  
821 3 $ok;
822 }
823  
824 3 1;
825  
826 __END__
« blib/lib/Alien/Build/Plugin/Fetch/NetFTP.pm ↑ Summary blib/lib/Alien/Build/Plugin/PkgConfig/LibPkgConf.pm »