blib/lib/Test/MinimumVersion.pm

filter: Statementstmt 80.4% 78 / 97 Branchbran 41.6% 10 / 24 Conditioncond 30.0% 9 / 30 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 76.1% 16 / 21 Podpod 100% 6 / 6 totaltotal 60.7% 119 / 196 CC 28 SCAR 28.9
CC
28
Cov
64%
minimum_version_ok
42.0
__from_meta
30.0
all_minimum_version_ok
12.8
CRAP 17.9
↑ Summary
1 1 ▶use v5.8;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 package Test::MinimumVersion;
5 1 $Test::MinimumVersion::VERSION = '0.101083';
6 # ABSTRACT: does your code require newer perl than you think?
7 1 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 #pod =head1 SYNOPSIS
10 #pod
11 #pod Example F<minimum-perl.t>:
12 #pod
13 #pod #!perl
14 #pod use Test::MinimumVersion;
15 #pod all_minimum_version_ok('5.008');
16 #pod
17 #pod =cut
18  
19 1 ▶use CPAN::Meta;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use File::Find::Rule;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use File::Find::Rule::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Perl::MinimumVersion 1.32; # numerous bugfies
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use version 0.70;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 1 ▶use Test::Builder;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 @Test::MinimumVersion::EXPORT = qw(
27 minimum_version_ok
28 all_minimum_version_ok
29 all_minimum_version_from_metayml_ok
30 all_minimum_version_from_metajson_ok
31 all_minimum_version_from_mymetayml_ok
32 all_minimum_version_from_mymetajson_ok
33 );
34  
35 1 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
36 1 my($self) = shift;
37 1 my $pack = caller;
38  
39 1 my $Test = Test::Builder->new;
40  
41 1 $Test->exported_to($pack);
42 1 $Test->plan(@_);
43  
44 1 $self->export_to_level(1, $self, @Test::MinimumVersion::EXPORT);
45 }
46  
47 4 ▶sub _objectify_version {
Subroutine _objectify_version: called CC=2 SCAR=6.9
48 4 my ($version) = @_;
49 4 ▶ $version = eval { $version->isa('version') }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $version->isa('version') } } ? : 1 3 4
50 ? $version
51 : version->new($version);
52 }
53  
54 #pod =func minimum_version_ok
55 #pod
56 #pod minimum_version_ok($file, $version);
57 #pod
58 #pod This test passes if the given file does not seem to require any version of perl
59 #pod newer than C<$version>, which may be given as a version string or a version
60 #pod object.
61 #pod
62 #pod =cut
63  
64 3 ▶sub minimum_version_ok {
Subroutine minimum_version_ok: called CC=13 SCAR=37.4
Pod documented
65 3 my ($file, $version) = @_;
66  
67 3 my $Test = Test::Builder->new;
68  
69 3 $version = _objectify_version($version);
70  
71 3 my $pmv = Perl::MinimumVersion->new($file);
72  
73 3 ▶ unless (defined $pmv) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pmv) 0 3 3
74 0 $Test->ok(0, $file);
75 0 $Test->diag(
76 "$file could not be parsed: " . PPI::Document->errstr
77 );
78 0 return;
79 }
80  
81 3 ▶ my $explicit_minimum = $pmv->minimum_explicit_version || 0;
Condition50%1/2
$pmv->minimum_explicit_version || 0
l!l
03
MC/DC0%0/1
$pmv->minimum_explicit_version || 0
$pmv->minimum_explicit_version
Truth table50%1/2
A
A= $pmv->minimum_explicit_version
Aresult
11
00
82 3 ▶ my $minimum = $pmv->minimum_syntax_version($explicit_minimum) || 0;
Condition50%1/2
$pmv->minimum_syntax_version($explicit_minimum) || 0
l!l
03
MC/DC0%0/1
$pmv->minimum_syntax_version($explicit_minimum) || 0
$pmv->minimum_syntax_version($explicit_minimum)
Truth table50%1/2
A
A= $pmv->minimum_syntax_version($explicit_minimum)
Aresult
11
00
83  
84 3 ▶ my $is_syntax = 1
Branch: 1 branch
BranchTrueFalseTotal
if $minimum and $minimum > $explicit_minimum 0 3 3
Condition33%1/3
$minimum and $minimum > $explicit_minimum
!ll&&!rl&&r
300
MC/DC0%0/2
$minimum and $minimum > $explicit_minimum
$minimum $minimum > $explicit_minimum
Truth table33%1/3
A and B
A= $minimumB= $minimum > $explicit_minimum
ABresult
0X0
100
111
85 if $minimum and $minimum > $explicit_minimum;
86  
87 3 ▶ $minimum = $explicit_minimum
Branch: 1 branch
BranchTrueFalseTotal
if $explicit_minimum and $explicit_minimum > $minimum 0 3 3
Condition33%1/3
$explicit_minimum and $explicit_minimum > $minimum
!ll&&!rl&&r
300
MC/DC0%0/2
$explicit_minimum and $explicit_minimum > $minimum
$explicit_minimum $explicit_minimum > $minimum
Truth table33%1/3
A and B
A= $explicit_minimumB= $explicit_minimum > $minimum
ABresult
0X0
100
111
88 if $explicit_minimum and $explicit_minimum > $minimum;
89  
90 3 my %min = $pmv->version_markers;
91  
92 3 ▶ if ($minimum <= $version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($minimum <= $version) { } 3 0 3
93 3 $Test->ok(1, $file);
94 } else {
95 0 $Test->ok(0, $file);
96 0 ▶ $Test->diag(
Branch: 1 branch
BranchTrueFalseTotal
$is_syntax ? : 0 0 0
97 "$file requires $minimum "
98 . ($is_syntax ? 'due to syntax' : 'due to explicit requirement')
99 );
100  
101 0 ▶ if ($is_syntax and my $markers = $min{ $minimum }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_syntax and my $markers = $min{$minimum}) 0 0 0
Condition0%0/3
$is_syntax and my $markers = $min{$minimum}
!ll&&!rl&&r
000
MC/DC0%0/2
$is_syntax and my $markers = $min{$minimum}
$is_syntax my $markers = $min{$minimum}
Truth table0%0/3
A and B
A= $is_syntaxB= my $markers = $min{$minimum}
ABresult
0X0
100
111
102 0 $Test->diag("version markers for $minimum:");
103 0 $Test->diag("- $_ ") for @$markers;
104 }
105 }
106 }
107  
108 #pod =func all_minimum_version_ok
109 #pod
110 #pod all_minimum_version_ok($version, \%arg);
111 #pod
112 #pod Given either a version string or a L<version> object, this routine produces a
113 #pod test plan (if there is no plan) and tests each relevant file with
114 #pod C<minimum_version_ok>.
115 #pod
116 #pod Relevant files are found by L<File::Find::Rule::Perl>.
117 #pod
118 #pod C<\%arg> is optional. Valid arguments are:
119 #pod
120 #pod paths - in what paths to look for files; defaults to (bin, script, t, lib,
121 #pod xt/smoke, and any .pm or .PL files in the current working
122 #pod directory) if it contains files, they will be checked
123 #pod no_plan - do not plan the tests about to be run
124 #pod skip - files to skip; this can be useful in weird cases like gigantic
125 #pod files, files falsely detected as Perl, or code that uses
126 #pod a source filter; this should be an arrayref of filenames
127 #pod
128 #pod =cut
129  
130 1 ▶sub all_minimum_version_ok {
Subroutine all_minimum_version_ok: called CC=11 SCAR=25.5
Pod documented
131 1 my ($version, $arg) = @_;
132 1 ▶ $arg ||= {};
Condition50%1/2
$arg ||= {}
l!l
10
MC/DC0%0/1
$arg ||= {}
$arg
Truth table50%1/2
A
A= $arg
Aresult
11
00
133 $arg->{paths} ||= [
134 1 ▶ qw(bin script lib t xt/smoke),
Condition50%1/2
$arg->{"paths"} ||= [("bin", "script", "lib", "t", "xt/smoke"), glob("*.pm"), glob("*.PL")]
l!l
01
MC/DC0%0/1
$arg->{"paths"} ||= [("bin", "script", "lib", "t", "xt/smoke"), glob("*.pm"), glob("*.PL")]
$arg->{"paths"}
Truth table50%1/2
A
A= $arg->{"paths"}
Aresult
11
00
135 1 ▶ glob("*.pm"),
Subroutine BEGIN: called CC=1 SCAR=0.0
136 glob("*.PL"),
137 ];
138  
139 1 ▶ $arg->{skip} ||= [];
Condition50%1/2
$arg->{"skip"} ||= []
l!l
10
MC/DC0%0/1
$arg->{"skip"} ||= []
$arg->{"skip"}
Truth table50%1/2
A
A= $arg->{"skip"}
Aresult
11
00
140  
141 1 my $Test = Test::Builder->new;
142  
143 1 $version = _objectify_version($version);
144  
145 1 my @perl_files;
146 1 for my $path (@{ $arg->{paths} }) {
147 5 ▶ if (-f $path and -s $path) {
Branch: 2 branches
BranchTrueFalseTotal
if (-f $path and -s $path) { } 0 5 5
elsif (-d $path) { } 1 4 5
Condition33%1/3
-f $path and -s $path
!ll&&!rl&&r
500
MC/DC0%0/2
-f $path and -s $path
-f $path -s $path
Truth table33%1/3
A and B
A= -f $pathB= -s $path
ABresult
0X0
100
111
148 0 push @perl_files, $path;
149 } elsif (-d $path) {
150 1 push @perl_files, File::Find::Rule->perl_file->in($path);
151 }
152 }
153  
154 1 my %skip = map {; $_ => 1 } @{ $arg->{skip} };
155 1 @perl_files = grep {; ! $skip{$_} } @perl_files;
156  
157 1 ▶ unless ($Test->has_plan or $arg->{no_plan}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Test->has_plan or $arg->{"no_plan"}) 1 0 1
Condition33%1/3
$Test->has_plan or $arg->{"no_plan"}
l!l&&r!l&&!r
001
MC/DC0%0/2
$Test->has_plan or $arg->{"no_plan"}
$Test->has_plan $arg->{"no_plan"}
Truth table33%1/3
A or B
A= $Test->has_planB= $arg->{"no_plan"}
ABresult
1X1
011
000
158 1 $Test->plan(tests => scalar @perl_files);
159 }
160  
161 1 minimum_version_ok($_, $version) for @perl_files;
162 }
163  
164 #pod =func all_minimum_version_from_metayml_ok
165 #pod
166 #pod all_minimum_version_from_metayml_ok(\%arg);
167 #pod
168 #pod This routine checks F<META.yml> for an entry in F<requires> for F<perl>. If no
169 #pod META.yml file or no perl version is found, all tests are skipped. If a version
170 #pod is found, the test proceeds as if C<all_minimum_version_ok> had been called
171 #pod with that version.
172 #pod
173 #pod =cut
174  
175 2 ▶sub __version_from_meta {
Subroutine __version_from_meta: called CC=1 SCAR=0.0
176 2 my ($fn) = @_;
177  
178 2 my $meta = CPAN::Meta->load_file($fn, { lazy_validation => 1 })->as_struct;
179 2 my $version = $meta->{prereqs}{runtime}{requires}{perl};
180 }
181  
182 0 ▶sub __from_meta {
Subroutine __from_meta: not called CC=5 SCAR=34.0
183 0 my ($fn, $arg) = @_;
184 0 ▶ $arg ||= {};
Condition0%0/2
$arg ||= {}
l!l
00
MC/DC0%0/1
$arg ||= {}
$arg
Truth table0%0/2
A
A= $arg
Aresult
11
00
185  
186 0 my $Test = Test::Builder->new;
187  
188 0 ▶ $Test->plan(skip_all => "$fn could not be found")
Branch: 1 branch
BranchTrueFalseTotal
unless -f $fn and -r _ 0 0 0
Condition0%0/3
-f $fn and -r _
!ll&&!rl&&r
000
MC/DC0%0/2
-f $fn and -r _
-f $fn -r _
Truth table0%0/3
A and B
A= -f $fnB= -r _
ABresult
0X0
100
111
189 unless -f $fn and -r _;
190  
191 0 ▶ $Test->plan(skip_all => "no minimum perl version could be determined")
Branch: 1 branch
BranchTrueFalseTotal
unless my $version = __version_from_meta($fn) 0 0 0
192 unless my $version = __version_from_meta($fn);
193  
194 0 all_minimum_version_ok($version, $arg);
195 }
196  
197 0 ▶sub all_minimum_version_from_metayml_ok {
Subroutine all_minimum_version_from_metayml_ok: not called CC=1 SCAR=6.9
Pod documented
198 0 __from_meta('META.yml', @_);
199 }
200  
201 #pod =func all_minimum_version_from_metajson_ok
202 #pod
203 #pod all_minimum_version_from_metajson_ok(\%arg);
204 #pod
205 #pod This routine checks F<META.json> for an entry in F<requires> for F<perl>. If
206 #pod no META.json file or no perl version is found, all tests are skipped. If a
207 #pod version is found, the test proceeds as if C<all_minimum_version_ok> had been
208 #pod called with that version.
209 #pod
210 #pod =cut
211  
212 0 ▶sub all_minimum_version_from_metajson_ok { __from_meta('META.json', @_); }
Subroutine all_minimum_version_from_metajson_ok: not called CC=1 SCAR=6.9
Pod documented
213  
214 #pod =func all_minimum_version_from_mymetayml_ok
215 #pod
216 #pod all_minimum_version_from_mymetayml_ok(\%arg);
217 #pod
218 #pod This routine checks F<MYMETA.yml> for an entry in F<requires> for F<perl>. If
219 #pod no MYMETA.yml file or no perl version is found, all tests are skipped. If a
220 #pod version is found, the test proceeds as if C<all_minimum_version_ok> had been
221 #pod called with that version.
222 #pod
223 #pod =cut
224  
225 0 ▶sub all_minimum_version_from_mymetayml_ok { __from_meta('MYMETA.yml', @_); }
Subroutine all_minimum_version_from_mymetayml_ok: not called CC=1 SCAR=6.9
Pod documented
226  
227 #pod =func all_minimum_version_from_mymetajson_ok
228 #pod
229 #pod all_minimum_version_from_mymetajson_ok(\%arg);
230 #pod
231 #pod This routine checks F<MYMETA.json> for an entry in F<requires> for F<perl>. If
232 #pod no MYMETA.json file or no perl version is found, all tests are skipped. If a
233 #pod version is found, the test proceeds as if C<all_minimum_version_ok> had been
234 #pod called with that version.
235 #pod
236 #pod =cut
237  
238 0 ▶sub all_minimum_version_from_mymetajson_ok { __from_meta('MYMETA.json', @_); }
Subroutine all_minimum_version_from_mymetajson_ok: not called CC=1 SCAR=6.9
Pod documented
239  
240 1 1;
241  
242 __END__
↑ Summary