blib/lib/Test/Needs.pm

filter: Statementstmt 40.4% 53 / 131 Branchbran 38.3% 33 / 86 Conditioncond 18.5% 5 / 27 MC/DCmcdc 11.7% 2 / 17 Subroutinesub 55.5% 10 / 18 Podpod 100% 1 / 1 totaltotal 37.1% 104 / 280 CC 57 SCAR 51.8
CC
57
Cov
37%
_fail_or_skip
552.0
BEGIN
17.6
_croak
12.0
CRAP 177.5
↑ Summary
1 package Test::Needs;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 our $VERSION = '0.002010';
6 2 $VERSION =~ tr/_//d;
7  
8 2 ▶BEGIN {
Subroutine BEGIN: called CC=7 SCAR=28.7
9 *_WORK_AROUND_HINT_LEAKAGE
10 = "$]" < 5.011 && !("$]" >= 5.009004 && "$]" < 5.010001)
11 2 ▶ ? sub(){1} : sub(){0};
Branch: 1 branch
BranchTrueFalseTotal
"$]" < 5.011 && !("$]" >= 5.009004 && "$]" < 5.010001) ? : 0 2 2
Condition16%1/6
"$]" < "5.011" and not "$]" >= "5.009004" && "$]" < "5.010001"
!ll&&!rl&&r
200
"$]" >= 5.009004 && "$]" < 5.010001
!ll&&!rl&&r
000
MC/DC0%0/3
"$]" < "5.011" and not "$]" >= "5.009004" && "$]" < "5.010001"
"$]" < "5.011" "$]" >= 5.009004 "$]" < 5.010001
Truth table25%1/4
A and not(B && C)
A= "$]" < "5.011"B= "$]" >= 5.009004C= "$]" < 5.010001
ABCresult
0XX0
1110
10X1
1101
12 *_WORK_AROUND_BROKEN_MODULE_STATE
13 = "$]" < 5.009
14 2 ▶ ? sub(){1} : sub(){0};
Branch: 1 branch
BranchTrueFalseTotal
"$]" < 5.009 ? : 0 2 2
15  
16 # this allows regexes to match wide characters in vstrings
17 2 ▶ if ("$]" >= 5.006001 && "$]" <= 5.006002) {
Branch: 1 branch
BranchTrueFalseTotal
if ("$]" >= "5.006001" and "$]" <= "5.006002") 0 2 2
Condition33%1/3
"$]" >= "5.006001" and "$]" <= "5.006002"
!ll&&!rl&&r
020
MC/DC0%0/2
"$]" >= "5.006001" and "$]" <= "5.006002"
"$]" >= "5.006001" "$]" <= "5.006002"
Truth table33%1/3
A and B
A= "$]" >= "5.006001"B= "$]" <= "5.006002"
ABresult
0X0
100
111
18 0 require utf8;
19 0 utf8->import;
20 }
21 }
22  
23 2 our @EXPORT = qw(test_needs);
24  
25 2 our $Level = 0;
26  
27 9 ▶sub _try_require {
Subroutine _try_require: called CC=4 SCAR=13.9
28 9 local %^H
29 if _WORK_AROUND_HINT_LEAKAGE;
30 9 my ($module) = @_;
31 9 (my $file = "$module.pm") =~ s{::|'}{/}g;
32 9 my $err;
33 {
34 9 local $@;
35 9 ▶ eval { require $file }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require $file } } or $err = $@ 3 6 9
36 or $err = $@;
37 }
38 9 ▶ if (defined $err) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $err) 6 3 9
39 6 delete $INC{$file}
40 if _WORK_AROUND_BROKEN_MODULE_STATE;
41 6 ▶ die $err
Branch: 1 branch
BranchTrueFalseTotal
unless $err =~ /\ACan't locate \Q$file\E/ 2 4 6
42 unless $err =~ /\ACan't locate \Q$file\E/;
43 4 return !1;
44 }
45 3 !0;
46 }
47  
48 0 ▶sub _croak {
Subroutine _croak: not called CC=3 SCAR=24.8
49 0 my $message = join '', @_;
50 0 my $i = 1;
51 0 ▶ while (my ($p, $f, $l) = caller($i++)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = caller $i++) 0 0 0
52 next
53 0 ▶ if $p =~ /\ATest::Needs(?:::|\z)/;
Branch: 1 branch
BranchTrueFalseTotal
if $p =~ /\ATest::Needs(?:::|\z)/ 0 0 0
54 0 die "$message at $f line $l.\n";
55 }
56 0 die $message;
57 }
58  
59 2 ▶sub _try_version {
Subroutine _try_version: called CC=1 SCAR=0.0
60 2 my ($module, $version) = @_;
61 2 local $@;
62 2 !!eval { $module->VERSION($version); 1 };
63 }
64  
65 50 ▶sub _numify_version {
Subroutine _numify_version: called CC=6 SCAR=18.4
66 50 for ($_[0]) {
67 return
68 50 ▶ !$_ ? 0
Branch: 4 branches
BranchTrueFalseTotal
!$_ ? : 0 50 50
/^[0-9]+(?:\.[0-9]+)?$/ ? : 14 36 50
/^v?([0-9]+(?:\.[0-9]+)*)$/ ? : 21 15 36
/^([\x05-\x07])(.*)$/s ? : 15 0 15
69 : /^[0-9]+(?:\.[0-9]+)?$/ ? sprintf('%.6f', $_)
70 : /^v?([0-9]+(?:\.[0-9]+)*)$/
71 ? sprintf('%d.%03d%03d', ((split /\./, $1), 0, 0)[0..2])
72 : /^([\x05-\x07])(.*)$/s
73 ? sprintf('%d.%03d%03d', ((map ord, /(.)/gs), 0, 0)[0..2])
74 : _croak qq{version "$_" does not look like a number};
75 }
76 }
77  
78 24 ▶sub _find_missing {
Subroutine _find_missing: called CC=10 SCAR=23.1
79 my @bad = map {
80 24 my ($module, $version) = @$_;
81 24 ▶ $module eq 'perl' ? do {
Branch: 1 branch
BranchTrueFalseTotal
$module eq 'perl' ? : 15 9 24
82 15 $version = _numify_version($version);
83 15 ▶ "$]" < $version ? (sprintf "perl %s (have %.6f)", $version, $]) : ()
Branch: 6 branches
BranchTrueFalseTotal
"$]" < $version ? : 5 10 15
$module =~ /^\d|[^\w:]|:::|[^:]:[^:]|^:|:$/ ? : 0 9 9
_try_require($module) ? : 3 4 7
defined $version && !_try_version($module, $version) ? : 1 2 3
defined $module->VERSION ? : 1 0 1
$version ? : 2 2 4
Condition100%3/3
defined $version and not _try_version($module, $version)
!ll&&!rl&&r
111
MC/DC100%2/2
defined $version and not _try_version($module, $version)
defined $version not _try_version($module, $version)
Truth table100%3/3
A and not(B)
A= defined $versionB= not _try_version($module, $version)
ABresult
0X0
100
111
84 }
85 : $module =~ /^\d|[^\w:]|:::|[^:]:[^:]|^:|:$/
86 ? _croak sprintf qq{"%s" does not look like a module name}, $module
87 : _try_require($module) ? (
88 defined $version && !_try_version($module, $version)
89 ? "$module $version (have ".(defined $module->VERSION ? $module->VERSION : 'undef').')'
90 : ()
91 )
92 : $version ? "$module $version"
93 : $module;
94 }
95 _pairs(@_);
96 22 ▶ @bad ? "Need " . join(', ', @bad) : undef;
Branch: 1 branch
BranchTrueFalseTotal
@bad ? : 10 12 22
97 }
98  
99 0 ▶sub import {
Subroutine import: not called CC=3 SCAR=20.0
100 0 my $class = shift;
101 0 my $target = caller;
102 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
103 0 local $Level = $Level + 1;
104 0 test_needs(@_);
105 }
106 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
107 0 *{"${target}::$_"} = \&{"${class}::$_"}
108 0 for @{"${class}::EXPORT"};
109 }
110  
111 0 ▶sub test_needs {
Subroutine test_needs: not called CC=3 SCAR=24.8
Pod documented
112 0 my $missing = _find_missing(@_);
113 0 local $Level = $Level + 1;
114 0 ▶ if ($missing) {
Branch: 1 branch
BranchTrueFalseTotal
if ($missing) 0 0 0
115 0 ▶ if ($ENV{RELEASE_TESTING}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'RELEASE_TESTING'}) { } 0 0 0
116 0 _fail("$missing due to RELEASE_TESTING");
117 }
118 else {
119 0 _skip($missing);
120 }
121 }
122 0 return 1;
123 }
124  
125 0 ▶sub _skip {
Subroutine _skip: not called CC=1 SCAR=6.9
126 0 local $Level = $Level + 1;
127 0 _fail_or_skip($_[0], 0)
128 }
129 0 ▶sub _fail {
Subroutine _fail: not called CC=1 SCAR=6.9
130 0 local $Level = $Level + 1;
131 0 _fail_or_skip($_[0], 1)
132 }
133  
134 24 ▶sub _pairs {
Subroutine _pairs: called CC=3 SCAR=11.0
135 map +(
136 ref eq 'HASH' ? do {
137 18 my $arg = $_;
138 18 ▶ map [ $_ => $arg->{$_} ], sort keys %$arg;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 2 4 6
139 }
140 24 ▶ : ref eq 'ARRAY' ? do {
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'HASH' ? : 18 6 24
141 2 my $arg = $_;
142 2 map [ @{$arg}[$_*2,$_*2+1] ], 0 .. int($#$arg / 2);
143 }
144 : [ $_ ]
145 ), @_;
146 }
147  
148 0 ▶sub _fail_or_skip {
Subroutine _fail_or_skip: not called CC=23 SCAR=63.1
149 0 my ($message, $fail) = @_;
150 0 ▶ if ($INC{'Test2/API.pm'}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($INC{'Test2/API.pm'}) { } 0 0 0
elsif ($INC{'Test/Builder.pm'}) { } 0 0 0
151 0 my $ctx = Test2::API::context(level => $Level);
152 0 my $hub = $ctx->hub;
153 0 ▶ if ($fail) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fail) { } 0 0 0
154 0 $ctx->ok(0, "Test::Needs modules available", [$message]);
155 }
156 else {
157 0 my $plan = $hub->plan;
158 0 my $tests = $hub->count;
159 0 ▶ if ($plan || $tests) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plan or $tests) { } 0 0 0
Condition0%0/3
$plan or $tests
l!l&&r!l&&!r
000
MC/DC0%0/2
$plan or $tests
$plan $tests
Truth table0%0/3
A or B
A= $planB= $tests
ABresult
1X1
011
000
160 0 ▶ my $skips
Branch: 1 branch
BranchTrueFalseTotal
$plan && $plan ne 'NO PLAN' ? : 0 0 0
Condition0%0/3
$plan and $plan ne "NO PLAN"
!ll&&!rl&&r
000
MC/DC0%0/2
$plan and $plan ne "NO PLAN"
$plan $plan ne "NO PLAN"
Truth table0%0/3
A and B
A= $planB= $plan ne "NO PLAN"
ABresult
0X0
100
111
161 = $plan && $plan ne 'NO PLAN' ? $plan - $tests : 1;
162 0 $ctx->skip("Test::Needs modules not available") for 1 .. $skips;
163 0 $ctx->note($message);
164 }
165 else {
166 0 $ctx->plan(0, 'SKIP', $message);
167 }
168 }
169 0 $ctx->done_testing;
170 0 ▶ $ctx->release if $Test2::API::VERSION < 1.302053;
Branch: 1 branch
BranchTrueFalseTotal
if $Test2::API::VERSION < "1.302053" 0 0 0
171 0 $ctx->send_event('+'._t2_terminate_event());
172 }
173 elsif ($INC{'Test/Builder.pm'}) {
174 0 local $Test::Builder::Level = $Test::Builder::Level + $Level;
175 0 my $tb = Test::Builder->new;
176 my $has_plan = Test::Builder->can('has_plan') ? 'has_plan'
177 0 ▶ : sub { $_[0]->expected_tests || eval { $_[0]->current_test($_[0]->current_test); 'no_plan' } };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 2 branches
BranchTrueFalseTotal
'Test::Builder'->can('has_plan') ? : 0 0 0
$_[0]->expected_tests or eval { do { $_[0]->current_test($_[0]->current_test); "no_plan" } } 0 0 0
178 0 my $tests = $tb->current_test;
179 0 ▶ if ($fail) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fail) { } 0 0 0
180 0 ▶ $tb->plan(tests => 1)
Branch: 1 branch
BranchTrueFalseTotal
unless $tb->$has_plan 0 0 0
181 unless $tb->$has_plan;
182 0 $tests++;
183 0 $tb->ok(0, "Test::Needs modules available");
184 0 $tb->diag($message);
185 }
186 else {
187 0 my $plan = $tb->$has_plan;
188 0 ▶ if ($plan || $tests) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plan or $tests) { } 0 0 0
Condition0%0/3
$plan or $tests
l!l&&r!l&&!r
000
MC/DC0%0/2
$plan or $tests
$plan $tests
Truth table0%0/3
A or B
A= $planB= $tests
ABresult
1X1
011
000
189 0 ▶ my $skips
Branch: 1 branch
BranchTrueFalseTotal
$plan && $plan ne 'no_plan' ? : 0 0 0
Condition0%0/3
$plan and $plan ne "no_plan"
!ll&&!rl&&r
000
MC/DC0%0/2
$plan and $plan ne "no_plan"
$plan $plan ne "no_plan"
Truth table0%0/3
A and B
A= $planB= $plan ne "no_plan"
ABresult
0X0
100
111
190 = $plan && $plan ne 'no_plan' ? $plan - $tests : 1;
191 $tb->skip("Test::Needs modules not available")
192 0 for 1 .. $skips;
193 0 $tests += $skips;
194 0 ▶ Test::Builder->can('note') ? $tb->note($message) : print "# $message\n";
Branch: 1 branch
BranchTrueFalseTotal
'Test::Builder'->can('note') ? : 0 0 0
195 }
196 else {
197 0 $tb->skip_all($message);
198 }
199 }
200 0 ▶ $tb->done_testing($tests)
Branch: 1 branch
BranchTrueFalseTotal
if "Test::Builder"->can("done_testing") 0 0 0
201 if Test::Builder->can('done_testing');
202 0 ▶ die bless {} => 'Test::Builder::Exception'
Branch: 1 branch
BranchTrueFalseTotal
if "Test::Builder"->can("parent") and $tb->parent 0 0 0
Condition0%0/3
"Test::Builder"->can("parent") and $tb->parent
!ll&&!rl&&r
000
MC/DC0%0/2
"Test::Builder"->can("parent") and $tb->parent
"Test::Builder"->can("parent") $tb->parent
Truth table0%0/3
A and B
A= "Test::Builder"->can("parent")B= $tb->parent
ABresult
0X0
100
111
203 if Test::Builder->can('parent') && $tb->parent;
204 }
205 else {
206 0 ▶ if ($fail) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fail) { } 0 0 0
207 0 print "1..1\n";
208 0 print "not ok 1 - Test::Needs modules available\n";
209 0 print STDERR "# $message\n";
210 0 exit 1;
211 }
212 else {
213 0 print "1..0 # SKIP $message\n";
214 }
215 }
216 0 exit 0;
217 }
218  
219 2 my $terminate_event;
220 0 ▶sub _t2_terminate_event () {
Subroutine _t2_terminate_event: not called CC=3 SCAR=24.8
221 0 ▶ return $terminate_event
Branch: 1 branch
BranchTrueFalseTotal
if $terminate_event 0 0 0
222 if $terminate_event;
223 0 local $@;
224 0 ▶ $terminate_event = eval sprintf <<'END_CODE', __LINE__+2, __FILE__ or die "$@";
Branch: 1 branch
BranchTrueFalseTotal
$terminate_event = eval "#line 226 \"/home/cpancover/.cpan/build/Test-Needs-0.002010-0/blib/lib/Test/Needs.pm\"\n package # hide\n Test::Needs::Event::Terminate;\n use Test2::Event ();\n our \@ISA = qw(Test2::Event);\n sub no_display { 1 }\n sub terminate { 0 }\n __PACKAGE__;\n" or die "$@" 0 0 0
225 #line %d "%s"
226 package # hide
227 Test::Needs::Event::Terminate;
228 use Test2::Event ();
229 our @ISA = qw(Test2::Event);
230 sub no_display { 1 }
231 sub terminate { 0 }
232 __PACKAGE__;
233 END_CODE
234 0 (my $pm = "$terminate_event.pm") =~ s{::}{/}g;
235 0 $INC{$pm} = __FILE__;
236 0 $terminate_event;
237 }
238  
239 2 1;
240 __END__
↑ Summary