| 1 | # ABSTRACT: Test that the POD of a module says what each sub takes, returns, and how it fails | ||||||||||||||
| 2 | # PODNAME: Test::Pod::Coverage::More | ||||||||||||||
| 3 | |||||||||||||||
| 4 | package Test::Pod::Coverage::More 0.001; | ||||||||||||||
| 5 | |||||||||||||||
| 6 | 2 | ▶ | use 5.036; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 2 | ▶ | use warnings FATAL => q{all}; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | 2 | ▶ | use Exporter qw{import}; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 2 | ▶ | use Test::Builder; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 2 | ▶ | use Test::Pod::Coverage (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | 2 | ▶ | use Pod::Coverage::More; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | |||||||||||||||
| 15 | # A test module exports its test functions, as Test::More and Test::Pod::Coverage do. | ||||||||||||||
| 16 | 2 | our @EXPORT = qw{pod_coverage_more_ok all_pod_coverage_more_ok}; ## no critic (Modules::ProhibitAutomaticExportation) | |||||||||||||
| 17 | |||||||||||||||
| 18 | |||||||||||||||
| 19 | 2 | our $TEST = Test::Builder->new; | |||||||||||||
| 20 | |||||||||||||||
| 21 | 4 | ▶ | sub pod_coverage_more_ok { | ||||||||||||
|
Subroutine
pod_coverage_more_ok: called CC=13 SCAR=28.5
Pod
documented
| |||||||||||||||
| 22 | 4 | my ( $module, $options, $name ) = @_; | |||||||||||||
| 23 | 4 | ▶ | my %args = %{ $options // {} }; | ||||||||||||
|
Condition100%2/2
$options // {}
MC/DC100%1/1
$options // {}
$options
Truth table100%2/2
A
A= $options
| |||||||||||||||
| 24 | 4 | ▶ | my $checks = delete( $args{checks} ) // \@Pod::Coverage::More::CHECKS; | ||||||||||||
|
Condition100%2/2
delete $args{"checks"} // \@Pod::Coverage::More::CHECKS
MC/DC100%1/1
delete $args{"checks"} // \@Pod::Coverage::More::CHECKS
delete $args{"checks"}
Truth table100%2/2
A
A= delete $args{"checks"}
| |||||||||||||||
| 25 | 4 | ▶ | $name //= "POD coverage of $module"; | ||||||||||||
|
Condition100%2/2
$name //= "POD coverage of $module"
MC/DC100%1/1
$name //= "POD coverage of $module"
$name
Truth table100%2/2
A
A= $name
| |||||||||||||||
| 26 | |||||||||||||||
| 27 | 4 | my $pc = Pod::Coverage::More->new( package => $module, %args ); | |||||||||||||
| 28 | 4 | my $rating = $pc->coverage; | |||||||||||||
| 29 | 4 | my @failures; | |||||||||||||
| 30 | 4 | ▶ | if ( !defined $rating ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 31 | 0 | ▶ | my $why = $pc->why_unrated // 'it could not be rated'; | ||||||||||||
|
Condition0%0/2
$pc->why_unrated // "it could not be rated"
MC/DC0%0/1
$pc->why_unrated // "it could not be rated"
$pc->why_unrated
Truth table0%0/2
A
A= $pc->why_unrated
| |||||||||||||||
| 32 | 0 | ▶ | push @failures, "$module: $why" if $why ne 'no public symbols defined'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 33 | } | ||||||||||||||
| 34 | elsif ( $rating < 1 ) { | ||||||||||||||
| 35 | 0 | push @failures, map { "$module: $_ is not documented" } sort $pc->naked; | |||||||||||||
| 36 | } | ||||||||||||||
| 37 | |||||||||||||||
| 38 | 4 | ▶ | my $report = $pc->coverage_report // {}; | ||||||||||||
|
Condition50%1/2
$pc->coverage_report // {}
MC/DC0%0/1
$pc->coverage_report // {}
$pc->coverage_report
Truth table50%1/2
A
A= $pc->coverage_report
| |||||||||||||||
| 39 | 4 | foreach my $sub ( sort keys %$report ) { | |||||||||||||
| 40 | 42 | foreach my $check (@$checks) { | |||||||||||||
| 41 | 30 | ▶ | push @failures, map { "$module: $_" } @{ $report->{$sub}{failures}{$check} || [] }; | ||||||||||||
|
Condition50%1/2
$report->{$sub}{'failures'}{$check} || []
MC/DC0%0/1
$report->{$sub}{'failures'}{$check} || []
$report->{$sub}{'failures'}{$check}
Truth table50%1/2
A
A= $report->{$sub}{'failures'}{$check}
| |||||||||||||||
| 42 | } | ||||||||||||||
| 43 | } | ||||||||||||||
| 44 | |||||||||||||||
| 45 | 4 | my $ok = $TEST->ok( !@failures, $name ); | |||||||||||||
| 46 | 4 | foreach my $failure (@failures) { | |||||||||||||
| 47 | 1 | $TEST->diag($failure); | |||||||||||||
| 48 | } | ||||||||||||||
| 49 | 4 | return $ok; | |||||||||||||
| 50 | } | ||||||||||||||
| 51 | |||||||||||||||
| 52 | |||||||||||||||
| 53 | 1 | ▶ | sub all_pod_coverage_more_ok { | ||||||||||||
|
Subroutine
all_pod_coverage_more_ok: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||
| 54 | 1 | my ($options) = @_; | |||||||||||||
| 55 | 1 | my @modules = Test::Pod::Coverage::all_modules(); | |||||||||||||
| 56 | 1 | ▶ | $TEST->plan( tests => scalar @modules ) if !$TEST->has_plan; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 57 | 1 | my $ok = 1; | |||||||||||||
| 58 | 1 | foreach my $module (@modules) { | |||||||||||||
| 59 | 1 | ▶ | $ok = 0 if !pod_coverage_more_ok( $module, $options ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 60 | } | ||||||||||||||
| 61 | 1 | return $ok; | |||||||||||||
| 62 | } | ||||||||||||||
| 63 | |||||||||||||||
| 64 | 2 | 1; | |||||||||||||
| 65 | |||||||||||||||
| 66 | __END__ | ||||||||||||||