| 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")
MC/DC0%0/1
$args->{"targets"} // Carp::croak("Targets must not be empty")
$args->{"targets"}
Truth table50%1/2
A
A= $args->{"targets"}
| |||||||||||||||||||||||||||||
| 24 | 1 | my $ignore_files = $args->{ignore_files}; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | if (defined $targets && ref $targets ne 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $targets and ref $targets ne "ARRAY"
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"
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $ignore_files and ref $ignore_files ne "ARRAY"
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"
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 45 | 3 | my $path_string = $path->stringify; | |||||||||||||||||||||||||||
| 46 | 3 | ▶ | if (!grep {$_ eq $path_string} @$ignore_files) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 1 | return; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 2 | 1; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | __END__ | ||||||||||||||||||||||||||||