Apocalypse/Dependencies.pm

filter: Statementstmt 35.0% 34 / 97 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 92.3% 12 / 13 Podpod 0.0% 0 / 1 totaltotal 28.2% 46 / 163 CC 31 SCAR 65.7
CC
31
Cov
24%
do_test
992.0
BEGIN
1.0
BEGIN
1.0
CRAP 715.4
↑ Summary Apocalypse/Kwalitee.pm »
1 #
2 # This file is part of Test-Apocalypse
3 #
4 # This software is copyright (c) 2014 by Apocalypse.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 38 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
10 package Test::Apocalypse::Dependencies;
11 38 $Test::Apocalypse::Dependencies::VERSION = '1.006';
12 38 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
13 38 $Test::Apocalypse::Dependencies::AUTHORITY = 'cpan:APOCAL';
14 }
15  
16 # ABSTRACT: Plugin to check for metadata dependencies
17  
18 38 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 38 ▶use File::Slurp 9999.13;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 38 ▶use YAML::Any 0.72;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 38 ▶use JSON::Any 1.25;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 38 ▶use File::Find::Rule 0.32;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 38 ▶use Perl::PrereqScanner 1.000;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 38 ▶use Test::Deep 0.108;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 38 ▶use CPAN::Meta::Requirements 2.113640;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 37 ▶sub _do_automated { 0 }
Subroutine _do_automated: called CC=1 SCAR=0.0
28  
29 0 ▶sub do_test {
Subroutine do_test: not called CC=31 SCAR=69.0
Pod undocumented
30 # load the metadata
31 0 my $runtime_req;
32 my $test_req;
33 0 my $provides;
34 0 ▶ if ( -e 'META.json' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (-e 'META.json') { } 0 0 0
elsif (-e 'META.yml') { } 0 0 0
35 0 my $file = read_file( 'META.json' );
36 0 my $metadata = JSON::Any->new->Load( $file );
37 0 $runtime_req = $metadata->{'prereqs'}{'runtime'}{'requires'};
38 0 $test_req = $metadata->{'prereqs'}{'test'}{'requires'};
39 0 ▶ $provides = $metadata->{'provides'} if exists $metadata->{'provides'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $metadata->{"provides"} 0 0 0
40 } elsif ( -e 'META.yml' ) {
41 0 my $file = read_file( 'META.yml' );
42 0 my $metadata = Load( $file );
43 0 $runtime_req = $metadata->{'requires'};
44 0 ▶ $provides = $metadata->{'provides'} if exists $metadata->{'provides'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $metadata->{"provides"} 0 0 0
45 } else {
46 0 die 'No META.(json|yml) found!';
47 }
48  
49 # Okay, scan the files
50 0 my $found_runtime = CPAN::Meta::Requirements->new;
51 0 my $found_test = CPAN::Meta::Requirements->new;
52 0 foreach my $file ( File::Find::Rule->file()->name( qr/\.pm$/ )->in( 'lib' ) ) {
53 0 $found_runtime->add_requirements( Perl::PrereqScanner->new->scan_file( $file ) );
54 }
55  
56 # scan the test dir only if we have test metadata
57 0 ▶ if ( defined $test_req ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $test_req) 0 0 0
58 0 foreach my $file ( File::Find::Rule->file()->name( qr/\.(pm|t|pl)$/ )->in( 't' ) ) {
59 0 $found_test->add_requirements( Perl::PrereqScanner->new->scan_file( $file ) );
60 }
61 }
62  
63 # Okay, the spec says that anything already in the runtime req shouldn't be listed in test req
64 # That means we need to "fake" the prereq and make sure the comparison is OK
65 0 ▶ if ( defined $test_req ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $test_req) 0 0 0
66 0 my %temp = %{ $found_test->as_string_hash };
67 0 foreach my $mod ( keys %temp ) {
68 0 ▶ if ( ! exists $test_req->{ $mod } and exists $runtime_req->{ $mod } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $test_req->{$mod} and exists $runtime_req->{$mod}) 0 0 0
Condition0%0/3
not exists $test_req->{$mod} and exists $runtime_req->{$mod}
!ll&&!rl&&r
000
MC/DC0%0/2
not exists $test_req->{$mod} and exists $runtime_req->{$mod}
not exists $test_req->{$mod} exists $runtime_req->{$mod}
Truth table0%0/3
not(A) and B
A= not exists $test_req->{$mod}B= exists $runtime_req->{$mod}
ABresult
0X0
100
111
69 # don't copy runtime_req's version because it might be different and cmp_deeply will complain!
70 0 $test_req->{ $mod } = $temp{ $mod };
71 }
72 }
73 }
74  
75 # We remove any prereqs that we provided in the package
76 0 ▶ if ( defined $provides ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $provides) 0 0 0
77 0 foreach my $p ( keys %$provides ) {
78 0 $found_runtime->clear_requirement( $p );
79 0 $found_test->clear_requirement( $p );
80 }
81 }
82  
83 # Thanks to PoCo::SmokeBox::Uploads::Rsync's use of PoCo::Generic, we have to do this
84 # Mangle the found version to the required one if it was 0
85 {
86 0 my %temp = %{ $found_runtime->as_string_hash };
87 0 foreach my $p ( keys %temp ) {
88 0 ▶ if ( $runtime_req->{ $p } ne '0' and $temp{ $p } eq '0' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($runtime_req->{$p} ne 0 and $temp{$p} eq 0) 0 0 0
Condition0%0/3
$runtime_req->{$p} ne 0 and $temp{$p} eq 0
!ll&&!rl&&r
000
MC/DC0%0/2
$runtime_req->{$p} ne 0 and $temp{$p} eq 0
$runtime_req->{$p} ne 0 $temp{$p} eq 0
Truth table0%0/3
A and B
A= $runtime_req->{$p} ne 0B= $temp{$p} eq 0
ABresult
0X0
100
111
89 0 $found_runtime->clear_requirement( $p );
90 0 $found_runtime->add_minimum( $p => $runtime_req->{ $p } );
91 }
92 }
93 }
94  
95 # Do the same for the test stuff
96 0 ▶ if ( defined $test_req ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $test_req) 0 0 0
97 0 my %temp = %{ $found_test->as_string_hash };
98 0 foreach my $p ( keys %temp ) {
99 0 ▶ if ( $test_req->{ $p } ne '0' and $temp{ $p } eq '0' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($test_req->{$p} ne 0 and $temp{$p} eq 0) 0 0 0
Condition0%0/3
$test_req->{$p} ne 0 and $temp{$p} eq 0
!ll&&!rl&&r
000
MC/DC0%0/2
$test_req->{$p} ne 0 and $temp{$p} eq 0
$test_req->{$p} ne 0 $temp{$p} eq 0
Truth table0%0/3
A and B
A= $test_req->{$p} ne 0B= $temp{$p} eq 0
ABresult
0X0
100
111
100 0 $found_test->clear_requirement( $p );
101 0 $found_test->add_minimum( $p => $runtime_req->{ $p } );
102 }
103 }
104 }
105  
106 # remove 'perl' dep - we check it in MinimumVersion anyway
107 0 ▶ delete $runtime_req->{'perl'} if exists $runtime_req->{'perl'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $runtime_req->{"perl"} 0 0 0
108 0 ▶ delete $test_req->{'perl'} if defined $test_req and exists $test_req->{'perl'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $test_req and exists $test_req->{"perl"} 0 0 0
Condition0%0/3
defined $test_req and exists $test_req->{"perl"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $test_req and exists $test_req->{"perl"}
defined $test_req exists $test_req->{"perl"}
Truth table0%0/3
A and B
A= defined $test_reqB= exists $test_req->{"perl"}
ABresult
0X0
100
111
109 0 $found_runtime->clear_requirement( 'perl' );
110 0 $found_test->clear_requirement( 'perl' );
111  
112 # Convert version objects to regular or we'll get something like this:
113 # Compared $data->{"Test\:\:NoPlan"}
114 # got : 'v0.0.6'
115 # expect : '0.0.6'
116 0 $found_runtime = $found_runtime->as_string_hash;
117 0 $found_runtime->{ $_ } =~ s/^v// for keys %$found_runtime;
118 0 $runtime_req->{ $_ } =~ s/^v// for keys %$runtime_req;
119  
120 # Do the actual comparison!
121 0 ▶ if ( defined $test_req ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $test_req) { } 0 0 0
122 0 plan tests => 2;
123  
124 0 $found_test = $found_test->as_string_hash;
125 0 $found_test->{ $_ } =~ s/^v// for keys %$found_test;
126 0 $test_req->{ $_ } =~ s/^v// for keys %$test_req;
127  
128 # TODO interesting, somewhere deep in the build chain it auto-upgraded Test::More version...
129 # I had 0.88 set but somehow 0.96 was in the META.yml argh!
130 0 ▶ if ( $found_test->{'Test::More'} ne $test_req->{'Test::More'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found_test->{"Test::More"} ne $test_req->{"Test::More"}) 0 0 0
131 0 diag( 'Found weird Test::More version mismatch, ignoring it! (' . $found_test->{'Test::More'} . ' vs ' . $test_req->{'Test::More'} . ')' );
132 0 $found_test->{'Test::More'} = $test_req->{'Test::More'};
133 }
134 } else {
135 0 plan tests => 1;
136 }
137  
138 0 cmp_deeply( $found_runtime, $runtime_req, "Runtime requires" );
139 0 ▶ cmp_deeply( $found_test, $test_req, "Test requires" ) if defined $test_req;
Branch: 1 branch
BranchTrueFalseTotal
if defined $test_req 0 0 0
140  
141 0 return;
142 }
143  
144 38 1;
145  
146 __END__
↑ Summary Apocalypse/Kwalitee.pm »