File Coverage

inc/Test2/Event/Plan.pm
Criterion Covered Total %
statement 26 39 66.6
branch 6 24 25.0
condition 2 11 18.1
subroutine 8 10 80.0
pod 4 5 80.0
total 46 89 51.6


line stmt bran cond sub pod time code
1             #line 1
2 1     1   4 package Test2::Event::Plan;
  1         1  
  1         21  
3 1     1   3 use strict;
  1         1  
  1         35  
4             use warnings;
5              
6             our $VERSION = '1.302073';
7              
8 1     1   3  
  1         38  
9 1     1   4 BEGIN { require Test2::Event; our @ISA = qw(Test2::Event) }
  1         1  
  1         4  
10             use Test2::Util::HashBase qw{max directive reason};
11 1     1   4  
  1         2  
  1         466  
12             use Carp qw/confess/;
13              
14             my %ALLOWED = (
15             'SKIP' => 1,
16             'NO PLAN' => 1,
17             );
18              
19 1 50   1 0 6 sub init {
20 0 0       0 if ($_[0]->{+DIRECTIVE}) {
21 0 0       0 $_[0]->{+DIRECTIVE} = 'SKIP' if $_[0]->{+DIRECTIVE} eq 'skip_all';
22             $_[0]->{+DIRECTIVE} = 'NO PLAN' if $_[0]->{+DIRECTIVE} eq 'no_plan';
23              
24 0 0       0 confess "'" . $_[0]->{+DIRECTIVE} . "' is not a valid plan directive"
25             unless $ALLOWED{$_[0]->{+DIRECTIVE}};
26             }
27             else {
28 1 50       120 confess "Cannot have a reason without a directive!"
29             if defined $_[0]->{+REASON};
30              
31 1 50       6 confess "No number of tests specified"
32             unless defined $_[0]->{+MAX};
33              
34 1 50       8 confess "Plan test count '" . $_[0]->{+MAX} . "' does not appear to be a valid positive integer"
35             unless $_[0]->{+MAX} =~ m/^\d+$/;
36 1         3  
37             $_[0]->{+DIRECTIVE} = '';
38             }
39             }
40              
41 0     0 1 0 sub sets_plan {
42             my $self = shift;
43             return (
44             $self->{+MAX},
45 0         0 $self->{+DIRECTIVE},
46             $self->{+REASON},
47             );
48             }
49              
50 1     1 1 2 sub callback {
51 1         2 my $self = shift;
52             my ($hub) = @_;
53 1   33     6  
54             $hub->plan($self->{+DIRECTIVE} || $self->{+MAX});
55 1 50       3  
56             return unless $self->{+DIRECTIVE};
57 0 0 0     0  
58             $hub->set_skip_reason($self->{+REASON} || 1) if $self->{+DIRECTIVE} eq 'SKIP';
59             }
60              
61 2     2 1 4 sub terminate {
62             my $self = shift;
63 2 50 33     7 # On skip_all we want to terminate the hub
64 2         5 return 0 if $self->{+DIRECTIVE} && $self->{+DIRECTIVE} eq 'SKIP';
65             return undef;
66             }
67              
68 0     0 1   sub summary {
69 0           my $self = shift;
70 0           my $max = $self->{+MAX};
71 0           my $directive = $self->{+DIRECTIVE};
72             my $reason = $self->{+REASON};
73 0 0 0        
74             return "Plan is $max assertions"
75             if $max || !$directive;
76 0 0          
77             return "Plan is '$directive', $reason"
78             if $reason;
79 0            
80             return "Plan is '$directive'";
81             }
82              
83             1;
84              
85             __END__