blib/lib/Test/Kwalitee.pm

filter: Statementstmt 98.6% 74 / 75 Branchbran 75.0% 15 / 20 Conditioncond 74.0% 20 / 27 MC/DCmcdc 50.0% 7 / 14 Subroutinesub 100% 10 / 10 Podpod 100% 1 / 1 totaltotal 86.3% 127 / 147 CC 22 SCAR 22.3
CC
22
Cov
89%
kwalitee_ok
14.0
_run_indicator
10.1
import
2.0
CRAP 9.3
↑ Summary
1 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Test::Kwalitee; # git description: v1.27-5-ge8333c9
4 # vim: set ts=8 sts=4 sw=4 tw=115 et :
5 # ABSTRACT: Test the Kwalitee of a distribution before you release it
6 # KEYWORDS: testing tests kwalitee CPANTS quality lint errors critic
7  
8 8 our $VERSION = '1.28';
9  
10 8 ▶use Cwd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use Test::Builder 0.88;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use Module::CPANTS::Analyse 0.92;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 8 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 our @EXPORT_OK = qw(kwalitee_ok);
16  
17 8 my $Test;
18 8 ▶BEGIN { $Test = Test::Builder->new }
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 sub import
21 10 ▶{
Subroutine import: called CC=2 SCAR=6.9
22 10 my ($class, @args) = @_;
23  
24 # back-compatibility mode!
25 10 ▶ if (@args % 2 == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (@args % 2 == 0) 8 2 10
26 {
27 8 $Test->level($Test->level + 1);
28 8 my %args = @args;
29 8 my $result = kwalitee_ok(@{$args{tests}});
30 8 $Test->done_testing;
31 8 return $result;
32 }
33  
34 # otherwise, do what a regular import would do...
35 2 $class->export_to_level(1, @_);
36 }
37  
38 sub kwalitee_ok
39 10 ▶{
Subroutine kwalitee_ok: called CC=14 SCAR=26.4
Pod documented
40 10 my (@tests) = @_;
41  
42 warn "These tests should not be running unless AUTHOR_TESTING=1 and/or RELEASE_TESTING=1!\n"
43 # this setting is internal and for this distribution only - there is
44 # no reason for you to need to circumvent this check in any other context.
45 # Please DO NOT enable this test to run for users, as it can fail
46 # unexpectedly as parts of the toolchain changes!
47 unless $ENV{_KWALITEE_NO_WARN} or $ENV{AUTHOR_TESTING} or $ENV{RELEASE_TESTING}
48 10 ▶ or (caller)[1] =~ m{^(?:\.[/\\])?xt\b}
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{"_KWALITEE_NO_WARN"} or $ENV{"AUTHOR_TESTING"} or $ENV{"RELEASE_TESTING"} or (caller)[1] =~ m(^(?:\.[/\\])?xt\b) or (caller)[0]->isa(__PACKAGE__) and (caller 1)[1] =~ m(^(?:\.[/\\])?xt\b) 1 9 10
Condition80%12/15
$ENV{"_KWALITEE_NO_WARN"} or $ENV{"AUTHOR_TESTING"} or $ENV{"RELEASE_TESTING"} or (caller)[1] =~ m(^(?:\.[/\\])?xt\b) or (caller)[0]->isa(__PACKAGE__) and (caller 1)[1] =~ m(^(?:\.[/\\])?xt\b)
l!l&&r!l&&!r
811
$ENV{"_KWALITEE_NO_WARN"} or $ENV{"AUTHOR_TESTING"} or $ENV{"RELEASE_TESTING"} or (caller)[1] =~ m(^(?:\.[/\\])?xt\b)
l!l&&r!l&&!r
712
$ENV{"_KWALITEE_NO_WARN"} or $ENV{"AUTHOR_TESTING"} or $ENV{"RELEASE_TESTING"}
l!l&&r!l&&!r
703
$ENV{"_KWALITEE_NO_WARN"} or $ENV{"AUTHOR_TESTING"}
l!l&&r!l&&!r
703
(caller)[0]->isa(__PACKAGE__) and (caller 1)[1] =~ m(^(?:\.[/\\])?xt\b)
!ll&&!rl&&r
011
MC/DC50%3/6
$ENV{"_KWALITEE_NO_WARN"} or $ENV{"AUTHOR_TESTING"} or $ENV{"RELEASE_TESTING"} or (caller)[1] =~ m(^(?:\.[/\\])?xt\b) or (caller)[0]->isa(__PACKAGE__) and (caller 1)[1] =~ m(^(?:\.[/\\])?xt\b)
$ENV{"_KWALITEE_NO_WARN"} $ENV{"AUTHOR_TESTING"} $ENV{"RELEASE_TESTING"} (caller)[1] =~ m(^(?:\.[/\\])?xt\b) (caller)[0]->isa(__PACKAGE__) (caller 1)[1] =~ m(^(?:\.[/\\])?xt\b)
Truth table57%4/7
A or B or C or D or E and F
A= $ENV{"_KWALITEE_NO_WARN"}B= $ENV{"AUTHOR_TESTING"}C= $ENV{"RELEASE_TESTING"}D= (caller)[1] =~ m(^(?:\.[/\\])?xt\b)E= (caller)[0]->isa(__PACKAGE__)F= (caller 1)[1] =~ m(^(?:\.[/\\])?xt\b)
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
0000111
00000X0
0000100
49 or ((caller)[0]->isa(__PACKAGE__) and (caller(1))[1] =~ m{^(?:\.[/\\])?xt\b});
50  
51 10 my @run_tests = grep { /^[^-]/ } @tests;
52 10 my @skip_tests = map { s/^-//; $_ } grep { /^-/ } @tests;
53  
54 # These don't really work unless you have a tarball, so skip them
55 10 push @skip_tests, qw(extractable extracts_nicely no_generated_files
56 has_proper_version has_version manifest_matches_dist);
57  
58 # MCA has a patch to add 'needs_tarball', 'no_build' as flags
59 10 my @skip_flags = qw(is_extra is_experimental needs_db);
60  
61 10 my $basedir = Cwd::cwd;
62  
63 10 my $analyzer = Module::CPANTS::Analyse->new({
64 distdir => $basedir,
65 dist => $basedir,
66 # for debugging..
67 opts => { no_capture => 1 },
68 });
69  
70 10 my $ok = 1;
71  
72 10 for my $generator (@{ $analyzer->mck->generators })
73 {
74 160 $generator->analyse($analyzer);
75  
76 160 for my $indicator (sort { $a->{name} cmp $b->{name} } @{ $generator->kwalitee_indicators })
77 {
78 330 ▶ next if grep { $indicator->{$_} } @skip_flags;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$indicator->{$_};} @skip_flags 140 190 330
79  
80 190 ▶ next if @run_tests and not grep { $indicator->{name} eq $_ } @run_tests;
Branch: 1 branch
BranchTrueFalseTotal
if @run_tests and not grep({$indicator->{"name"} eq $_;} @run_tests) 136 54 190
Condition100%3/3
@run_tests and not grep({$indicator->{"name"} eq $_;} @run_tests)
!ll&&!rl&&r
3816136
MC/DC100%2/2
@run_tests and not grep({$indicator->{"name"} eq $_;} @run_tests)
@run_tests not grep({$indicator->{"name"} eq $_;} @run_tests)
Truth table100%3/3
A and not(B)
A= @run_testsB= not grep({$indicator->{"name"} eq $_;} @run_tests)
ABresult
0X0
100
111
81  
82 54 ▶ next if grep { $indicator->{name} eq $_ } @skip_tests;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$indicator->{"name"} eq $_;} @skip_tests 4 50 54
83  
84 50 my $result = _run_indicator($analyzer->d, $indicator);
85 50 ▶ $ok &&= $result;
Condition100%3/3
$ok &&= $result
!ll&&!rl&&r
1148
MC/DC100%2/2
$ok &&= $result
$ok $result
Truth table100%3/3
A &&= B
A= $okB= $result
ABresult
0X0
100
111
86 }
87 }
88  
89 10 return $ok;
90 }
91  
92 sub _run_indicator
93 50 ▶{
Subroutine _run_indicator: called CC=8 SCAR=23.2
94 50 my ($dist, $metric) = @_;
95  
96 50 my $subname = $metric->{name};
97 50 my $ok = 1;
98  
99 50 $Test->level($Test->level + 1);
100 50 ▶ if (not $Test->ok( $metric->{code}->($dist), $subname))
Branch: 1 branch
BranchTrueFalseTotal
unless ($Test->ok($metric->{"code"}->($dist), $subname)) 1 49 50
101 {
102 1 $ok = 0;
103 1 $Test->diag('Error: ', $metric->{error});
104  
105 # NOTE: this is poking into the analyse structures; we really should
106 # have a formal API for accessing this.
107  
108 # attempt to print all the extra information we have
109 1 my @details;
110 push @details, $metric->{details}->($dist)
111 1 ▶ if $metric->{details} and ref $metric->{details} eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if $metric->{"details"} and ref $metric->{"details"} eq "CODE" 1 0 1
Condition33%1/3
$metric->{"details"} and ref $metric->{"details"} eq "CODE"
!ll&&!rl&&r
001
MC/DC0%0/2
$metric->{"details"} and ref $metric->{"details"} eq "CODE"
$metric->{"details"} ref $metric->{"details"} eq "CODE"
Truth table33%1/3
A and B
A= $metric->{"details"}B= ref $metric->{"details"} eq "CODE"
ABresult
0X0
100
111
112 push @details,
113 (ref $dist->{error}{$subname}
114 0 ? @{$dist->{error}{$subname}}
115 : $dist->{error}{$subname})
116 1 ▶ if defined $dist->{error} and defined $dist->{error}{$subname};
Branch: 2 branches
BranchTrueFalseTotal
if defined $dist->{"error"} and defined $dist->{"error"}{$subname} 0 1 1
ref $dist->{'error'}{$subname} ? : 0 0 0
Condition33%1/3
defined $dist->{"error"} and defined $dist->{"error"}{$subname}
!ll&&!rl&&r
100
MC/DC0%0/2
defined $dist->{"error"} and defined $dist->{"error"}{$subname}
defined $dist->{"error"} defined $dist->{"error"}{$subname}
Truth table33%1/3
A and B
A= defined $dist->{"error"}B= defined $dist->{"error"}{$subname}
ABresult
0X0
100
111
117 1 ▶ $Test->diag("Details:\n", join("\n", @details)) if @details;
Branch: 1 branch
BranchTrueFalseTotal
if @details 1 0 1
118  
119 1 $Test->diag('Remedy: ', $metric->{remedy});
120 }
121 50 $Test->level($Test->level - 1);
122  
123 50 return $ok;
124 }
125  
126 8 1;
127  
128 __END__
↑ Summary