| 1 | package Dist::Conformance 0.006; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Whether the development harness of a repository conforms to its standards, and bringing it up to date | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use 5.040; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use re '/aasx'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Mojo::Base -base, -signatures; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use List::Util(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Module::Runtime(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Mojo::File(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Dist::Conformance::Check(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Dist::Conformance::Config(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Dist::Conformance::Flavor(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Dist::Conformance::Schema(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use Dist::Conformance::Snapshot::Directory(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Dist::Conformance::Source::Directory(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use Dist::Conformance::Source::Git(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Dist::Conformance::Update(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | has 'root'; | |||||||||||||||||||||||||||
| 25 | 0 | ▶ | has snapshot => sub ($self) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | die "Dist::Conformance needs a root or a snapshot\n" if !defined $self->root; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | return Dist::Conformance::Snapshot::Directory->new( root => $self->root ); | |||||||||||||||||||||||||||
| 28 | 1 | }; | |||||||||||||||||||||||||||
| 29 | 0 | ▶ | has config => sub ($self) { Dist::Conformance::Config::load( $self->snapshot ) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 30 | 1 | has 'cache'; | |||||||||||||||||||||||||||
| 31 | 1 | has offline => 0; | |||||||||||||||||||||||||||
| 32 | 1 | has 'standards'; | |||||||||||||||||||||||||||
| 33 | 0 | ▶ | has source => sub ($self) { $self->build_source }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | has flavor => sub ($self) { Dist::Conformance::Flavor->load( $self->source, $self->config->{flavor} ) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub build_source ($self) { | ||||||||||||||||||||||||||
|
Subroutine
build_source: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 0 | my $config = $self->config->{source}; | |||||||||||||||||||||||||||
| 39 | 0 | ▶ | my %path = ( path => $config->{path} // q{} ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$config->{"path"} // ""
MC/DC0%0/1
$config->{"path"} // ""
$config->{"path"}
Truth table0%0/2
A
A= $config->{"path"}
| |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if ( defined $self->standards ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | return Dist::Conformance::Source::Directory->new( directory => $self->standards, %path ); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if ( defined $config->{git} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | my %options = ( url => $config->{git}, offline => $self->offline, %path ); | |||||||||||||||||||||||||||
| 45 | 0 | ▶ | $options{ref} = $config->{ref} if defined $config->{ref}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | $options{cache} = $self->cache if defined $self->cache; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | return Dist::Conformance::Source::Git->new(%options); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 0 | my $directory = Mojo::File->new( $config->{directory} ); | |||||||||||||||||||||||||||
| 50 | 0 | ▶ | $directory = Mojo::File->new( $self->root )->child( $config->{directory} ) if !$directory->is_abs && defined $self->root; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $directory->is_abs and defined $self->root
MC/DC0%0/2
not $directory->is_abs and defined $self->root
not $directory->is_abs
defined $self->root
Truth table0%0/3
not(A) and B
A= not $directory->is_absB= defined $self->root
| |||||||||||||||||||||||||||||
| 51 | 0 | return Dist::Conformance::Source::Directory->new( directory => "$directory", %path ); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub skipped ($self) { | ||||||||||||||||||||||||||
|
Subroutine
skipped: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | 0 | my $config = $self->config; | |||||||||||||||||||||||||||
| 57 | 0 | my $flavor = $self->flavor; | |||||||||||||||||||||||||||
| 58 | 0 | my %runs = map { $_ => 1 } $flavor->check_names; | |||||||||||||||||||||||||||
| 59 | my @wrong = ( | ||||||||||||||||||||||||||||
| 60 | 0 | ( map { "/skip/$_" } grep { !$runs{ $config->{skip}[$_] } } 0 .. $#{ $config->{skip} } ), | |||||||||||||||||||||||||||
| 61 | 0 | ( map { "/checks/$_" } grep { !$runs{$_} } sort keys %{ $config->{checks} } ), | |||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if (@wrong) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | my $name = $flavor->name; | |||||||||||||||||||||||||||
| 65 | 0 | Dist::Conformance::Schema::refuse( $Dist::Conformance::Config::FILE, map { "$_: names a check that the flavor $name does not run" } @wrong ); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | 0 | return { map { $_ => 1 } @{ $config->{skip} } }; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub checks ($self) { | ||||||||||||||||||||||||||
|
Subroutine
checks: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | return $self->{checks} //= do { | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"checks"} //= do {
my $flavor = $self->flavor;
my $skipped = $self->skipped;
my(%merged) = %{$flavor->checks;};
Dist::Conformance::Flavor::merge_checks(\%merged, $self->config->{"checks"});
my(%variables) = (%{$flavor->variables;}, %{$self->config->{"variables"};});
[map({$self->make_check($_, $merged{$_}, \%variables);} grep({not $skipped->{$_};} $flavor->check_names))]
}
MC/DC0%0/2
$self->{"checks"} //= do {
my $flavor = $self->flavor;
my $skipped = $self->skipped;
my(%merged) = %{$flavor->checks;};
Dist::Conformance::Flavor::merge_checks(\%merged, $self->config->{"checks"});
my(%variables) = (%{$flavor->variables;}, %{$self->config->{"variables"};});
[map({$self->make_check($_, $merged{$_}, \%variables);} grep({not $skipped->{$_};} $flavor->check_names))]
}
$self->{"checks"}
do {
my $flavor = $self->flavor;
my $skipped = $self->skipped;
my(%merged) = %{$flavor->checks;};
Dist::Conformance::Flavor::merge_checks(\%merged, $self->config->{"checks"});
my(%variables) = (%{$flavor->variables;}, %{$self->config->{"variables"};});
[map({$self->make_check($_, $merged{$_}, \%variables);} grep({not $skipped->{$_};} $flavor->check_names))]
}
Truth table0%0/3
A //= B
A= $self->{"checks"}B= do {
my $flavor = $self->flavor;
my $skipped = $self->skipped;
my(%merged) = %{$flavor->checks;};
Dist::Conformance::Flavor::merge_checks(\%merged, $self->config->{"checks"});
my(%variables) = (%{$flavor->variables;}, %{$self->config->{"variables"};});
[map({$self->make_check($_, $merged{$_}, \%variables);} grep({not $skipped->{$_};} $flavor->check_names))]
}
| |||||||||||||||||||||||||||||
| 73 | 0 | my $flavor = $self->flavor; | |||||||||||||||||||||||||||
| 74 | 0 | my $skipped = $self->skipped; | |||||||||||||||||||||||||||
| 75 | 0 | my %merged = %{ $flavor->checks }; | |||||||||||||||||||||||||||
| 76 | 0 | Dist::Conformance::Flavor::merge_checks( \%merged, $self->config->{checks} ); | |||||||||||||||||||||||||||
| 77 | 0 | my %variables = ( %{ $flavor->variables }, %{ $self->config->{variables} } ); | |||||||||||||||||||||||||||
| 78 | [ | ||||||||||||||||||||||||||||
| 79 | 0 | map { $self->make_check( $_, $merged{$_}, \%variables ) } | |||||||||||||||||||||||||||
| 80 | 0 | grep { !$skipped->{$_} } $flavor->check_names | |||||||||||||||||||||||||||
| 81 | ]; | ||||||||||||||||||||||||||||
| 82 | }; | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub make_check ( $self, $name, $config, $variables ) { | ||||||||||||||||||||||||||
|
Subroutine
make_check: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 0 | my $flavor = $self->flavor->name; | |||||||||||||||||||||||||||
| 88 | 0 | ▶ | my $module = $config->{module} // $name; | ||||||||||||||||||||||||||
|
Condition0%0/3
$config->{"module"} // $name
MC/DC0%0/2
$config->{"module"} // $name
$config->{"module"}
$name
Truth table0%0/3
A // B
A= $config->{"module"}B= $name
| |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | my $class = index( $module, '::' ) >= 0 ? $module : "Dist::Conformance::Check::$module"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | if ( !Dist::Conformance::Schema::matches( $Dist::Conformance::Check::MODULE, $class ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | die "The flavor $flavor runs the check $name, but $class is not the name of a module\n"; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if ( !eval { Module::Runtime::require_module($class); 1 } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | die( "The flavor $flavor runs the check $name, but its module $class does not load: " . Dist::Conformance::Schema::first_line($@), "\n" ); | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 0 | ▶ | die "The flavor $flavor runs the check $name, but $class is not a Dist::Conformance::Check\n" if !$class->isa('Dist::Conformance::Check'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | my $repo = exists $self->config->{checks}{$name} ? " with $Dist::Conformance::Config::FILE" : q{}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | return $class->from_config( | |||||||||||||||||||||||||||
| 99 | name => $name, | ||||||||||||||||||||||||||||
| 100 | config => $config, | ||||||||||||||||||||||||||||
| 101 | source => $self->source, | ||||||||||||||||||||||||||||
| 102 | variables => $variables, | ||||||||||||||||||||||||||||
| 103 | where => "the check $name of the flavor $flavor$repo", | ||||||||||||||||||||||||||||
| 104 | ); | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 1 | our %STATUSES = map { $_ => 1 } qw{pass fail info}; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub check ($self) { | ||||||||||||||||||||||||||
|
Subroutine
check: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 111 | 0 | my $snapshot = $self->snapshot; | |||||||||||||||||||||||||||
| 112 | 0 | my %run = map { $_->name => $_ } @{ $self->checks }; | |||||||||||||||||||||||||||
| 113 | 0 | my @results; | |||||||||||||||||||||||||||
| 114 | 0 | for my $name ( $self->flavor->check_names ) { | |||||||||||||||||||||||||||
| 115 | 0 | my $check = $run{$name}; | |||||||||||||||||||||||||||
| 116 | 0 | ▶ | if ( !$check ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 0 | push @results, { check => $name, status => 'skip', detail => "skipped by $Dist::Conformance::Config::FILE" }; | |||||||||||||||||||||||||||
| 118 | 0 | next; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | 0 | my ( $status, $detail ) = eval { $check->check($snapshot) }; | |||||||||||||||||||||||||||
| 121 | 0 | ▶ | if ( !defined $status ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 122 | 0 | ( $status, $detail ) = ( 'fail', 'the check died: ' . Dist::Conformance::Schema::first_line($@) ); | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | elsif ( !$STATUSES{$status} ) { | ||||||||||||||||||||||||||||
| 125 | 0 | ( $status, $detail ) = ( 'fail', "the check returned the status $status, which is not pass, fail or info" ); | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | 0 | ▶ | $status = 'info' if $status eq 'fail' && $check->config->{level} eq 'info'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$status eq "fail" and $check->config->{"level"} eq "info"
MC/DC0%0/2
$status eq "fail" and $check->config->{"level"} eq "info"
$status eq "fail"
$check->config->{"level"} eq "info"
Truth table0%0/3
A and B
A= $status eq "fail"B= $check->config->{"level"} eq "info"
| |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | push @results, { check => $name, status => $status, detail => $detail // q{} }; | ||||||||||||||||||||||||||
|
Condition0%0/2
$detail // ""
MC/DC0%0/1
$detail // ""
$detail
Truth table0%0/2
A
A= $detail
| |||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | 0 | return \@results; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub update ( $self, %options ) { | ||||||||||||||||||||||||||
|
Subroutine
update: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 135 | 0 | my @results; | |||||||||||||||||||||||||||
| 136 | 0 | for my $check ( @{ $self->checks } ) { | |||||||||||||||||||||||||||
| 137 | 0 | ▶ | my $update = Dist::Conformance::Update->new( snapshot => $self->snapshot, dry_run => $options{dry_run} // 0 ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$options{"dry_run"} // 0
MC/DC0%0/1
$options{"dry_run"} // 0
$options{"dry_run"}
Truth table0%0/2
A
A= $options{"dry_run"}
| |||||||||||||||||||||||||||||
| 138 | 0 | ▶ | if ( !eval { $check->update($update); 1 } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 0 | $update->by_hand( 'The update died: ' . Dist::Conformance::Schema::first_line($@) ); | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | 0 | push @results, { check => $check->name, changes => $update->changes, manual => $update->manual }; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | 0 | return \@results; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | ▶ | sub failed ($results) { | ||||||||||||||||||||||||||
|
Subroutine
failed: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 148 | 0 | ▶ | return List::Util::any { $_->{status} eq 'fail' } @$results; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | __END__ | ||||||||||||||||||||||||||||