blib/lib/Test2/Event/Plan.pm

filter: Statementstmt 100% 46 / 46 Branchbran 96.8% 31 / 32 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 10 / 10 Podpod 80.0% 4 / 5 totaltotal 96.1% 99 / 103 CC 19 SCAR 16.4
CC
19
Cov
98%
init
8.0
facet_data
7.0
summary
4.0
CRAP 5.1
« blib/lib/Test2/Util/Sub.pm ↑ Summary blib/lib/Test2/Hub/Subtest.pm »
1 package Test2::Event::Plan;
2 455 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 455 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 455 our $VERSION = '1.302226';
6  
7  
8 455 ▶BEGIN { require Test2::Event; our @ISA = qw(Test2::Event) }
Subroutine BEGIN: called CC=1 SCAR=0.0
9 455 ▶use Test2::Util::HashBase qw{max directive reason};
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 455 ▶use Carp qw/confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 455 my %ALLOWED = (
14 'SKIP' => 1,
15 'NO PLAN' => 1,
16 );
17  
18 1221 ▶sub init {
Subroutine init: called CC=8 SCAR=20.8
Pod undocumented
19 1221 ▶ if ($_[0]->{+DIRECTIVE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{'directive'}) { } 66 1155 1221
20 66 ▶ $_[0]->{+DIRECTIVE} = 'SKIP' if $_[0]->{+DIRECTIVE} eq 'skip_all';
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"directive"} eq "skip_all" 5 61 66
21 66 ▶ $_[0]->{+DIRECTIVE} = 'NO PLAN' if $_[0]->{+DIRECTIVE} eq 'no_plan';
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"directive"} eq "no_plan" 2 64 66
22  
23 confess "'" . $_[0]->{+DIRECTIVE} . "' is not a valid plan directive"
24 66 ▶ unless $ALLOWED{$_[0]->{+DIRECTIVE}};
Branch: 1 branch
BranchTrueFalseTotal
unless $ALLOWED{$_[0]{"directive"}} 1 65 66
25 }
26 else {
27 confess "Cannot have a reason without a directive!"
28 1155 ▶ if defined $_[0]->{+REASON};
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0]{"reason"} 1 1154 1155
29  
30 confess "No number of tests specified"
31 1154 ▶ unless defined $_[0]->{+MAX};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0]{"max"} 1 1153 1154
32  
33 confess "Plan test count '" . $_[0]->{+MAX} . "' does not appear to be a valid positive integer"
34 1153 ▶ unless $_[0]->{+MAX} =~ m/^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]{"max"} =~ /^\d+$/ 1 1152 1153
35  
36 1152 $_[0]->{+DIRECTIVE} = '';
37 }
38 }
39  
40 3 ▶sub sets_plan {
Subroutine sets_plan: called CC=1 SCAR=0.0
Pod documented
41 3 my $self = shift;
42 return (
43 $self->{+MAX},
44 $self->{+DIRECTIVE},
45 3 $self->{+REASON},
46 );
47 }
48  
49 212 ▶sub terminate {
Subroutine terminate: called CC=3 SCAR=11.0
Pod documented
50 212 my $self = shift;
51 # On skip_all we want to terminate the hub
52 212 ▶ return 0 if $self->{+DIRECTIVE} && $self->{+DIRECTIVE} eq 'SKIP';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"directive"} and $self->{"directive"} eq "SKIP" 1 211 212
Condition100%3/3
$self->{"directive"} and $self->{"directive"} eq "SKIP"
!ll&&!rl&&r
20921
MC/DC100%2/2
$self->{"directive"} and $self->{"directive"} eq "SKIP"
$self->{"directive"} $self->{"directive"} eq "SKIP"
Truth table100%3/3
A and B
A= $self->{"directive"}B= $self->{"directive"} eq "SKIP"
ABresult
0X0
100
111
53 211 return undef;
54 }
55  
56 3 ▶sub summary {
Subroutine summary: called CC=4 SCAR=13.9
Pod documented
57 3 my $self = shift;
58 3 my $max = $self->{+MAX};
59 3 my $directive = $self->{+DIRECTIVE};
60 3 my $reason = $self->{+REASON};
61  
62 3 ▶ return "Plan is $max assertions"
Branch: 1 branch
BranchTrueFalseTotal
if $max or not $directive 1 2 3
Condition66%2/3
$max or not $directive
l!l&&r!l&&!r
102
MC/DC50%1/2
$max or not $directive
$max not $directive
Truth table66%2/3
A or not(B)
A= $maxB= not $directive
ABresult
1X1
011
000
63 if $max || !$directive;
64  
65 2 ▶ return "Plan is '$directive', $reason"
Branch: 1 branch
BranchTrueFalseTotal
if $reason 1 1 2
66 if $reason;
67  
68 1 return "Plan is '$directive'";
69 }
70  
71 3956 ▶sub facet_data {
Subroutine facet_data: called CC=7 SCAR=19.5
Pod documented
72 3956 my $self = shift;
73  
74 3956 my $out = $self->common_facet_data;
75  
76 $out->{control}->{terminate} = $self->{+DIRECTIVE} eq 'SKIP' ? 0 : undef
77 3956 ▶ unless defined $out->{control}->{terminate};
Branch: 2 branches
BranchTrueFalseTotal
unless defined $out->{"control"}{"terminate"} 3956 0 3956
$self->{'directive'} eq 'SKIP' ? : 502 3454 3956
78  
79 3956 $out->{plan} = {count => $self->{+MAX}};
80 3956 ▶ $out->{plan}->{details} = $self->{+REASON} if defined $self->{+REASON};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"reason"} 497 3459 3956
81  
82 3956 ▶ if (my $dir = $self->{+DIRECTIVE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dir = $self->{"directive"}) 505 3451 3956
83 505 ▶ $out->{plan}->{skip} = 1 if $dir eq 'SKIP';
Branch: 1 branch
BranchTrueFalseTotal
if $dir eq "SKIP" 502 3 505
84 505 ▶ $out->{plan}->{none} = 1 if $dir eq 'NO PLAN';
Branch: 1 branch
BranchTrueFalseTotal
if $dir eq "NO PLAN" 3 502 505
85 }
86  
87 3956 return $out;
88 }
89  
90  
91 455 1;
92  
93 __END__
« blib/lib/Test2/Util/Sub.pm ↑ Summary blib/lib/Test2/Hub/Subtest.pm »