Test/Perl/Lint.pm

filter: Statementstmt 91.0% 61 / 67 Branchbran 50.0% 10 / 20 Conditioncond 37.5% 3 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 11 / 11 Podpod 100% 1 / 1 totaltotal 76.7% 86 / 112 CC 17 SCAR 25.7
CC
17
Cov
78%
all_policies_ok
22.2
__ANON__
3.0
BEGIN
1.0
CRAP 13.0
« Perl/Lint/Policy/ValuesAndExpressions/ProhibitLongChainsOfMethodCalls.pm ↑ Summary Perl/Lint.pm »
1 package Test::Perl::Lint;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use parent qw/Test::Builder::Module/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 my @test_more_exports;
8 2 ▶BEGIN { @test_more_exports = (qw/done_testing/) }
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Test::More import => \@test_more_exports;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Path::Tiny 0.068 qw/path/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Perl::Lint;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 our $VERSION = "0.25";
15  
16 2 our @EXPORT = (@test_more_exports, qw/all_policies_ok/);
17  
18 1 ▶sub all_policies_ok {
Subroutine all_policies_ok: called CC=15 SCAR=31.0
Pod documented
19 1 local $Test::Builder::Level = $Test::Builder::Level + 2;
20  
21 1 my ($args) = @_;
22  
23 1 ▶ my $targets = $args->{targets} // Carp::croak "Targets must not be empty";
Condition50%1/2
$args->{"targets"} // Carp::croak("Targets must not be empty")
l!l
10
MC/DC0%0/1
$args->{"targets"} // Carp::croak("Targets must not be empty")
$args->{"targets"}
Truth table50%1/2
A
A= $args->{"targets"}
Aresult
11
00
24 1 my $ignore_files = $args->{ignore_files};
25  
26 1 ▶ if (defined $targets && ref $targets ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $targets and ref $targets ne "ARRAY") 0 1 1
Condition33%1/3
defined $targets and ref $targets ne "ARRAY"
!ll&&!rl&&r
010
MC/DC0%0/2
defined $targets and ref $targets ne "ARRAY"
defined $targets ref $targets ne "ARRAY"
Truth table33%1/3
A and B
A= defined $targetsB= ref $targets ne "ARRAY"
ABresult
0X0
100
111
27 0 Carp::croak 'Target directories are must be an array reference';
28 }
29  
30 1 ▶ if (defined $ignore_files && ref $ignore_files ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ignore_files and ref $ignore_files ne "ARRAY") 0 1 1
Condition33%1/3
defined $ignore_files and ref $ignore_files ne "ARRAY"
!ll&&!rl&&r
010
MC/DC0%0/2
defined $ignore_files and ref $ignore_files ne "ARRAY"
defined $ignore_files ref $ignore_files ne "ARRAY"
Truth table33%1/3
A and B
A= defined $ignore_filesB= ref $ignore_files ne "ARRAY"
ABresult
0X0
100
111
31 0 Carp::croak 'Ignore files are must be an array reference';
32 }
33  
34 my $linter = Perl::Lint->new({
35 ignore => $args->{ignore_policies},
36 filter => $args->{filter},
37 1 });
38  
39 1 my @paths;
40 1 for my $target (@$targets) {
41 1 ▶ if (-d $target) {
Branch: 2 branches
BranchTrueFalseTotal
if (-d $target) { } 1 0 1
elsif (-f $target) { } 0 0 0
42 3 ▶ path($target)->visit(sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
43 3 my ($path) = @_;
44 3 ▶ if ($path->is_file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path->is_file) 3 0 3
45 3 my $path_string = $path->stringify;
46 3 ▶ if (!grep {$_ eq $path_string} @$ignore_files) {
Branch: 1 branch
BranchTrueFalseTotal
if (not grep({$_ eq $path_string;} @$ignore_files)) 2 1 3
47 2 push @paths, $path_string;
48 }
49 }
50 1 }, {recurse => 1});
51 }
52 elsif (-f $target) {
53 0 ▶ if (!grep {$_ eq $target} @$ignore_files) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_ eq $target;} @$ignore_files) 0 0 0
54 0 push @paths, $target;
55 }
56 }
57 else {
58 0 Carp::carp "'$target' doesn't exist";
59 }
60 }
61 1 @paths = sort {$a cmp $b} @paths;
62  
63 1 for my $path_string (@paths) {
64 2 my $violations = $linter->lint($path_string);
65 2 ▶ if (scalar @$violations == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$violations == 0) { } 1 1 2
66 1 Test::More::pass(__PACKAGE__ . ' for ' . $path_string);
67 }
68 else {
69 1 my $package = __PACKAGE__;
70 1 my $error_msg = <<"...";
71  
72 $package found these violations in "$path_string":
73 ...
74  
75 1 for my $violation (@$violations) {
76 1 my $explanation = $violation->{explanation};
77 1 ▶ if (ref $explanation eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $explanation eq "ARRAY") 1 0 1
78 1 $explanation = 'See page ' . join(', ', @$explanation) . ' of PBP';
79 }
80 1 $error_msg .= <<"...";
81 $violation->{description} at line $violation->{line}. $explanation.
82 ...
83 }
84  
85 1 ▶ Test::More::ok(0, "$package for $path_string") or Test::More::diag($error_msg);
Branch: 1 branch
BranchTrueFalseTotal
&Test::More::ok(0, "$package for $path_string") or Test::More::diag($error_msg) 0 1 1
86 }
87 }
88  
89 1 return;
90 }
91  
92 2 1;
93  
94 __END__
« Perl/Lint/Policy/ValuesAndExpressions/ProhibitLongChainsOfMethodCalls.pm ↑ Summary Perl/Lint.pm »