Apocalypse/Kwalitee.pm

filter: Statementstmt 38.5% 32 / 83 Branchbran 15.6% 5 / 32 Conditioncond 0.0% 0 / 24 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 72.7% 8 / 11 Podpod 0.0% 0 / 1 totaltotal 26.9% 45 / 167 CC 29 SCAR 52.5
CC
29
Cov
27%
do_test
380.0
_cleanup_debian_files
30.0
_get_tarball
8.1
CRAP 190.5
« Apocalypse/Dependencies.pm ↑ Summary Apocalypse/PPPort.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::Kwalitee;
11 38 $Test::Apocalypse::Kwalitee::VERSION = '1.006';
12 38 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
13 38 $Test::Apocalypse::Kwalitee::AUTHORITY = 'cpan:APOCAL';
14 }
15  
16 # ABSTRACT: Plugin for Test::Kwalitee
17  
18 38 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 38 ▶use Module::CPANTS::Analyse 0.95;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 38 ▶use version 0.77;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 0 ▶sub _do_automated { 0 }
Subroutine _do_automated: not called CC=1 SCAR=6.9
23  
24 # init CPANTS with the latest tarball
25 38 my $tarball;
26 37 ▶sub _is_disabled {
Subroutine _is_disabled: called CC=3 SCAR=11.3
27 37 $tarball = _get_tarball( '.' );
28 37 ▶ if ( ! defined $tarball ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $tarball) 37 0 37
29 # Dist::Zilla-specific code, the tarball we want is 3 levels up ( when using dzp::TestRelease :)
30 # [@Apocalyptic/TestRelease] Extracting /home/apoc/mygit/perl-pod-weaver-pluginbundle-apocalyptic/Pod-Weaver-PluginBundle-Apocalyptic-0.001.tar.gz to .build/MiNXla4CY7
31 37 $tarball = _get_tarball( '../../..' );
32 37 ▶ if ( ! defined $tarball ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $tarball) 37 0 37
33 37 return 'Distribution tarball not found, unable to run CPANTS Kwalitee tests!';
34 }
35 }
36 }
37  
38 # the following code was copied/plagarized/transformed from Test::Kwalitee, thanks!
39 # The reason why I didn't just use that module is because it doesn't print the kwalitee or consider extra metrics...
40 0 ▶sub do_test {
Subroutine do_test: not called CC=19 SCAR=59.4
Pod undocumented
41 0 my $analyzer = Module::CPANTS::Analyse->new({
42 'dist' => $tarball,
43 });
44  
45 # set the number of tests / run analyzer
46 0 my @indicators = $analyzer->mck()->get_indicators();
47 0 plan tests => scalar @indicators;
48 0 $analyzer->unpack;
49 0 $analyzer->analyse;
50 0 $analyzer->calc_kwalitee;
51 0 my $kwalitee_points = 0;
52 0 my $available_kwalitee = 0;
53  
54 # loop over the kwalitee metrics
55 0 foreach my $gen ( @{ $analyzer->mck()->generators() } ) {
56 0 foreach my $metric ( @{ $gen->kwalitee_indicators() } ) {
57 # get the result
58 0 my $result = $metric->{'code'}->( $analyzer->d(), $metric );
59 0 my $type = 'CORE';
60 0 ▶ if ( exists $metric->{'is_experimental'} and $metric->{'is_experimental'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $metric->{"is_experimental"} and $metric->{"is_experimental"}) 0 0 0
Condition0%0/3
exists $metric->{"is_experimental"} and $metric->{"is_experimental"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $metric->{"is_experimental"} and $metric->{"is_experimental"}
exists $metric->{"is_experimental"} $metric->{"is_experimental"}
Truth table0%0/3
A and B
A= exists $metric->{"is_experimental"}B= $metric->{"is_experimental"}
ABresult
0X0
100
111
61 0 $type = 'EXPERIMENTAL';
62 }
63 0 ▶ if ( exists $metric->{'is_extra'} and $metric->{'is_extra'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $metric->{"is_extra"} and $metric->{"is_extra"}) 0 0 0
Condition0%0/3
exists $metric->{"is_extra"} and $metric->{"is_extra"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $metric->{"is_extra"} and $metric->{"is_extra"}
exists $metric->{"is_extra"} $metric->{"is_extra"}
Truth table0%0/3
A and B
A= exists $metric->{"is_extra"}B= $metric->{"is_extra"}
ABresult
0X0
100
111
64 0 $type = 'EXTRA';
65 }
66  
67 0 ▶ if ( $type eq 'CORE' or $result ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'CORE' or $result) { } 0 0 0
Condition0%0/3
$type eq "CORE" or $result
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "CORE" or $result
$type eq "CORE" $result
Truth table0%0/3
A or B
A= $type eq "CORE"B= $result
ABresult
1X1
011
000
68 0 ok( $result, "[$type] $metric->{'name'}" );
69 } else {
70 0 ▶ if ( ! $ENV{PERL_APOCALYPSE} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ENV{'PERL_APOCALYPSE'}) { } 0 0 0
71 # non-core tests PASS automatically for ease of use
72 0 pass( "[$type] $metric->{'name'} treated as PASS" );
73 } else {
74 0 fail( "[$type] $metric->{'name'}" );
75 }
76 }
77  
78 # print more diag if it failed
79 0 ▶ if ( ! $result && $ENV{TEST_VERBOSE} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $result and $ENV{"TEST_VERBOSE"}) 0 0 0
Condition0%0/3
not $result and $ENV{"TEST_VERBOSE"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $result and $ENV{"TEST_VERBOSE"}
not $result $ENV{"TEST_VERBOSE"}
Truth table0%0/3
not(A) and B
A= not $resultB= $ENV{"TEST_VERBOSE"}
ABresult
0X0
100
111
80 0 diag( '[' . $metric->{'name'} . '] error(' . $metric->{'error'} . ') remedy(' . $metric->{'remedy'} . ')' );
81 0 ▶ if ( $metric->{'name'} eq 'prereq_matches_use' or $metric->{'name'} eq 'build_prereq_matches_use' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($metric->{"name"} eq "prereq_matches_use" or $metric->{"name"} eq "build_prereq_matches_use") 0 0 0
Condition0%0/3
$metric->{"name"} eq "prereq_matches_use" or $metric->{"name"} eq "build_prereq_matches_use"
l!l&&r!l&&!r
000
MC/DC0%0/2
$metric->{"name"} eq "prereq_matches_use" or $metric->{"name"} eq "build_prereq_matches_use"
$metric->{"name"} eq "prereq_matches_use" $metric->{"name"} eq "build_prereq_matches_use"
Truth table0%0/3
A or B
A= $metric->{"name"} eq "prereq_matches_use"B= $metric->{"name"} eq "build_prereq_matches_use"
ABresult
1X1
011
000
82 0 require Data::Dumper; ## no critic (Bangs::ProhibitDebuggingModules)
83 0 diag( "module information: " . Data::Dumper::Dumper( $analyzer->d->{'uses'} ) );
84 }
85 }
86  
87 # should we tally up the kwalitee?
88 0 ▶ if ( ! exists $metric->{'is_experimental'} || ! $metric->{'is_experimental'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $metric->{"is_experimental"} and $metric->{"is_experimental"}) 0 0 0
Condition0%0/3
exists $metric->{"is_experimental"} and $metric->{"is_experimental"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $metric->{"is_experimental"} and $metric->{"is_experimental"}
exists $metric->{"is_experimental"} $metric->{"is_experimental"}
Truth table0%0/3
A and B
A= exists $metric->{"is_experimental"}B= $metric->{"is_experimental"}
ABresult
0X0
100
111
89 # we increment available only for CORE, not extra
90 0 ▶ if ( ! exists $metric->{'is_extra'} || ! $metric->{'is_extra'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $metric->{"is_extra"} and $metric->{"is_extra"}) 0 0 0
Condition0%0/3
exists $metric->{"is_extra"} and $metric->{"is_extra"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $metric->{"is_extra"} and $metric->{"is_extra"}
exists $metric->{"is_extra"} $metric->{"is_extra"}
Truth table0%0/3
A and B
A= exists $metric->{"is_extra"}B= $metric->{"is_extra"}
ABresult
0X0
100
111
91 0 $available_kwalitee++;
92 }
93 0 ▶ if ( $result ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result) 0 0 0
94 0 $kwalitee_points++;
95 }
96 }
97 }
98 }
99  
100 # for diag, print out the kwalitee of the module
101 0 diag( "Kwalitee rating: " . sprintf( "%.2f%%", 100 * ( $kwalitee_points / $available_kwalitee ) ) . " [$kwalitee_points / $available_kwalitee]" );
102  
103 # That piece of crap dumps files all over :(
104 0 _cleanup_debian_files();
105  
106 0 return;
107 }
108  
109 74 ▶sub _get_tarball {
Subroutine _get_tarball: called CC=5 SCAR=20.9
110 74 my $path = shift;
111  
112 # get our list of stuff, and try to find the latest tarball
113 74 ▶ opendir( my $dir, $path ) or die "Unable to opendir: $!";
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dir, $path or die "Unable to opendir: $!" 74 0 74
114 74 my @dirlist = readdir( $dir );
115 74 ▶ closedir( $dir ) or die "Unable to closedir: $!";
Branch: 1 branch
BranchTrueFalseTotal
closedir $dir or die "Unable to closedir: $!" 74 0 74
116  
117 # get the tarballs
118 74 @dirlist = grep { /(?:tar(?:\.gz|\.bz2)?|tgz|zip)$/ } @dirlist;
119  
120 # short-circuit
121 74 ▶ if ( scalar @dirlist == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @dirlist == 0) 74 0 74
122 74 return;
123 }
124  
125 # get the versions
126 0 @dirlist = map { [ $_, $_ ] } @dirlist;
127 0 for ( @dirlist ) {
128 0 $_->[0] =~ s/^.*\-([^\-]+)(?:tar(?:\.gz|\.bz2)?|tgz|zip)$/$1/;
129 0 $_->[0] = version->new( $_->[0] );
130 }
131  
132 # sort by version
133 0 @dirlist = reverse sort { $a->[0] <=> $b->[0] } @dirlist;
134  
135 # TODO should we use file::spec and stuff here?
136 0 return $path . '/' . $dirlist[0]->[1];
137 }
138  
139 # Module::CPANTS::Kwalitee::Distros suck!
140 #t/a_manifest..............1/1
141 ## Failed test at t/a_manifest.t line 13.
142 ## got: 1
143 ## expected: 0
144 ## The following files are not named in the MANIFEST file: /home/apoc/workspace/VCS-perl-trunk/VCS-2.12.2/Debian_CPANTS.txt
145 ## Looks like you failed 1 test of 1.
146 #t/a_manifest.............. Dubious, test returned 1 (wstat 256, 0x100)
147 0 ▶sub _cleanup_debian_files {
Subroutine _cleanup_debian_files: not called CC=5 SCAR=34.0
148 0 foreach my $file ( qw( Debian_CPANTS.txt ../Debian_CPANTS.txt ) ) {
149 0 ▶ if ( -e $file and -f _ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $file and -f _) 0 0 0
Condition0%0/3
-e $file and -f _
!ll&&!rl&&r
000
MC/DC0%0/2
-e $file and -f _
-e $file -f _
Truth table0%0/3
A and B
A= -e $fileB= -f _
ABresult
0X0
100
111
150 0 my $status = unlink( $file );
151 0 ▶ if ( ! $status ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($status) 0 0 0
152 0 warn "unable to unlink $file";
153 }
154 }
155 }
156  
157 0 return;
158 }
159  
160 38 1;
161  
162 __END__
« Apocalypse/Dependencies.pm ↑ Summary Apocalypse/PPPort.pm »