File Coverage

blib/lib/Test/Apocalypse/Kwalitee.pm
Criterion Covered Total %
statement 17 84 20.2
branch 0 34 0.0
condition 0 24 0.0
subroutine 7 11 63.6
pod 0 1 0.0
total 24 154 15.5


line stmt bran cond sub pod time code
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 39     39   7169066 use strict; use warnings;
  39     39   82  
  39         1257  
  39         161  
  39         39  
  39         1882  
10             package Test::Apocalypse::Kwalitee;
11             $Test::Apocalypse::Kwalitee::VERSION = '1.003';
12             BEGIN {
13 39     39   512 $Test::Apocalypse::Kwalitee::AUTHORITY = 'cpan:APOCAL';
14             }
15              
16             # ABSTRACT: Plugin for Test::Kwalitee
17              
18 39     39   157 use Test::More;
  39         199  
  39         301  
19 39     39   28867 use Module::CPANTS::Analyse 0.95;
  39         5135989  
  39         350  
20 39     39   1677 use version 0.77;
  39         555  
  39         294  
21              
22 38     38   190 sub _do_automated { 0 }
23              
24             sub do_test {
25             # the following code was copied/plagarized/transformed from Test::Kwalitee, thanks!
26             # The reason why I didn't just use that module is because it doesn't print the kwalitee or consider extra metrics...
27              
28             # init CPANTS with the latest tarball
29 0     0 0   my $tarball = _get_tarball( '.' );
30 0 0         if ( ! defined $tarball ) {
31             # Dist::Zilla-specific code, the tarball we want is 3 levels up ( when using dzp::TestRelease :)
32             # [@Apocalyptic/TestRelease] Extracting /home/apoc/mygit/perl-pod-weaver-pluginbundle-apocalyptic/Pod-Weaver-PluginBundle-Apocalyptic-0.001.tar.gz to .build/MiNXla4CY7
33 0           $tarball = _get_tarball( '../../..' );
34 0 0         if ( ! defined $tarball ) {
35 0           plan skip_all => 'Distribution tarball not found, unable to run CPANTS Kwalitee tests!';
36 0           return;
37             }
38             }
39              
40 0 0         _analyze( $tarball ) if defined $tarball;
41              
42 0           return;
43             }
44              
45             sub _analyze {
46 0     0     my $tarball = shift;
47              
48 0           my $analyzer = Module::CPANTS::Analyse->new({
49             'dist' => $tarball,
50             });
51              
52             # set the number of tests / run analyzer
53 0           my @indicators = $analyzer->mck()->get_indicators();
54 0           plan tests => scalar @indicators;
55 0           $analyzer->unpack;
56 0           $analyzer->analyse;
57 0           $analyzer->calc_kwalitee;
58 0           my $kwalitee_points = 0;
59 0           my $available_kwalitee = 0;
60              
61             # loop over the kwalitee metrics
62 0           foreach my $gen ( @{ $analyzer->mck()->generators() } ) {
  0            
63 0           foreach my $metric ( @{ $gen->kwalitee_indicators() } ) {
  0            
64             # get the result
65 0           my $result = $metric->{'code'}->( $analyzer->d(), $metric );
66 0           my $type = 'CORE';
67 0 0 0       if ( exists $metric->{'is_experimental'} and $metric->{'is_experimental'} ) {
68 0           $type = 'EXPERIMENTAL';
69             }
70 0 0 0       if ( exists $metric->{'is_extra'} and $metric->{'is_extra'} ) {
71 0           $type = 'EXTRA';
72             }
73              
74 0 0 0       if ( $type eq 'CORE' or $result ) {
75 0           ok( $result, "[$type] $metric->{'name'}" );
76             } else {
77 0 0         if ( ! $ENV{PERL_APOCALYPSE} ) {
78             # non-core tests PASS automatically for ease of use
79 0           pass( "[$type] $metric->{'name'} treated as PASS" );
80             } else {
81 0           fail( "[$type] $metric->{'name'}" );
82             }
83             }
84              
85             # print more diag if it failed
86 0 0 0       if ( ! $result && $ENV{TEST_VERBOSE} ) {
87 0           diag( '[' . $metric->{'name'} . '] error(' . $metric->{'error'} . ') remedy(' . $metric->{'remedy'} . ')' );
88 0 0 0       if ( $metric->{'name'} eq 'prereq_matches_use' or $metric->{'name'} eq 'build_prereq_matches_use' ) {
89 0           require Data::Dumper; ## no critic (Bangs::ProhibitDebuggingModules)
90 0           diag( "module information: " . Data::Dumper::Dumper( $analyzer->d->{'uses'} ) );
91             }
92             }
93              
94             # should we tally up the kwalitee?
95 0 0 0       if ( ! exists $metric->{'is_experimental'} || ! $metric->{'is_experimental'} ) {
96             # we increment available only for CORE, not extra
97 0 0 0       if ( ! exists $metric->{'is_extra'} || ! $metric->{'is_extra'} ) {
98 0           $available_kwalitee++;
99             }
100 0 0         if ( $result ) {
101 0           $kwalitee_points++;
102             }
103             }
104             }
105             }
106              
107             # for diag, print out the kwalitee of the module
108 0           diag( "Kwalitee rating: " . sprintf( "%.2f%%", 100 * ( $kwalitee_points / $available_kwalitee ) ) . " [$kwalitee_points / $available_kwalitee]" );
109              
110             # That piece of crap dumps files all over :(
111 0           _cleanup_debian_files();
112              
113 0           return;
114             }
115              
116             sub _get_tarball {
117 0     0     my $path = shift;
118              
119             # get our list of stuff, and try to find the latest tarball
120 0 0         opendir( my $dir, $path ) or die "Unable to opendir: $!";
121 0           my @dirlist = readdir( $dir );
122 0 0         closedir( $dir ) or die "Unable to closedir: $!";
123              
124             # get the tarballs
125 0           @dirlist = grep { /(?:tar(?:\.gz|\.bz2)?|tgz|zip)$/ } @dirlist;
  0            
126              
127             # short-circuit
128 0 0         if ( scalar @dirlist == 0 ) {
129 0           return;
130             }
131              
132             # get the versions
133 0           @dirlist = map { [ $_, $_ ] } @dirlist;
  0            
134 0           for ( @dirlist ) {
135 0           $_->[0] =~ s/^.*\-([^\-]+)(?:tar(?:\.gz|\.bz2)?|tgz|zip)$/$1/;
136 0           $_->[0] = version->new( $_->[0] );
137             }
138              
139             # sort by version
140 0           @dirlist = reverse sort { $a->[0] <=> $b->[0] } @dirlist;
  0            
141              
142             # TODO should we use file::spec and stuff here?
143 0           return $path . '/' . $dirlist[0]->[1];
144             }
145              
146             # Module::CPANTS::Kwalitee::Distros suck!
147             #t/a_manifest..............1/1
148             ## Failed test at t/a_manifest.t line 13.
149             ## got: 1
150             ## expected: 0
151             ## The following files are not named in the MANIFEST file: /home/apoc/workspace/VCS-perl-trunk/VCS-2.12.2/Debian_CPANTS.txt
152             ## Looks like you failed 1 test of 1.
153             #t/a_manifest.............. Dubious, test returned 1 (wstat 256, 0x100)
154             sub _cleanup_debian_files {
155 0     0     foreach my $file ( qw( Debian_CPANTS.txt ../Debian_CPANTS.txt ) ) {
156 0 0 0       if ( -e $file and -f _ ) {
157 0           my $status = unlink( $file );
158 0 0         if ( ! $status ) {
159 0           warn "unable to unlink $file";
160             }
161             }
162             }
163              
164 0           return;
165             }
166              
167             1;
168              
169             __END__
170              
171             =pod
172              
173             =encoding UTF-8
174              
175             =for :stopwords Apocalypse Niebur Ryan kwalitee
176              
177             =for Pod::Coverage do_test
178              
179             =head1 NAME
180              
181             Test::Apocalypse::Kwalitee - Plugin for Test::Kwalitee
182              
183             =head1 VERSION
184              
185             This document describes v1.003 of Test::Apocalypse::Kwalitee - released October 24, 2014 as part of Test-Apocalypse.
186              
187             =head1 DESCRIPTION
188              
189             Encapsulates L<Test::Kwalitee> functionality. This plugin also processes the extra metrics, and prints out the kwalitee as a diag() for info.
190              
191             =head1 SEE ALSO
192              
193             Please see those modules/websites for more information related to this module.
194              
195             =over 4
196              
197             =item *
198              
199             L<Test::Apocalypse|Test::Apocalypse>
200              
201             =back
202              
203             =head1 AUTHOR
204              
205             Apocalypse <APOCAL@cpan.org>
206              
207             =head1 COPYRIGHT AND LICENSE
208              
209             This software is copyright (c) 2014 by Apocalypse.
210              
211             This is free software; you can redistribute it and/or modify it under
212             the same terms as the Perl 5 programming language system itself.
213              
214             The full text of the license can be found in the
215             F<LICENSE> file included with this distribution.
216              
217             =head1 DISCLAIMER OF WARRANTY
218              
219             THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
220             APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
221             HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
222             OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
223             THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
224             PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
225             IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
226             ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
227              
228             IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
229             WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
230             THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
231             GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
232             USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
233             DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
234             PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
235             EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
236             SUCH DAMAGES.
237              
238             =cut