blib/lib/Test2/Tools/Basic.pm

filter: Statementstmt 96.3% 78 / 81 Branchbran 72.2% 13 / 18 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 17 / 17 Podpod 100% 11 / 11 totaltotal 91.1% 123 / 135 CC 13 SCAR 9.5
CC
13
Cov
90%
plan
5.2
todo
4.0
skip
3.0
CRAP 2.6
« blib/lib/Test2/Tools/Defer.pm ↑ Summary blib/lib/Test2/Event/Generic.pm »
1 package Test2::Tools::Basic;
2 182 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 182 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 182 our $VERSION = '1.302226';
6  
7 182 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 182 ▶use Test2::API qw/context/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 182 our @EXPORT = qw{
11 ok pass fail diag note todo skip
12 plan skip_all done_testing bail_out
13 };
14 182 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 700 ▶sub ok($;$@) {
Subroutine ok: called CC=2 SCAR=6.9
Pod documented
17 700 my ($bool, $name, @diag) = @_;
18 700 my $ctx = context();
19 700 $ctx->ok($bool, $name, \@diag);
20 700 $ctx->release;
21 698 ▶ return $bool ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$bool ? : 670 28 698
22 }
23  
24 10 ▶sub pass {
Subroutine pass: called CC=1 SCAR=0.0
Pod documented
25 10 my ($name) = @_;
26 10 my $ctx = context();
27 10 $ctx->ok(1, $name);
28 10 $ctx->release;
29 10 return 1;
30 }
31  
32 2 ▶sub fail {
Subroutine fail: called CC=1 SCAR=0.0
Pod documented
33 2 my ($name, @diag) = @_;
34 2 my $ctx = context();
35 2 $ctx->ok(0, $name, \@diag);
36 2 $ctx->release;
37 2 return 0;
38 }
39  
40 12 ▶sub diag {
Subroutine diag: called CC=1 SCAR=0.0
Pod documented
41 12 my $ctx = context();
42 12 $ctx->diag( join '', grep { defined $_ } @_ );
43 12 $ctx->release;
44 12 return 0;
45 }
46  
47 662 ▶sub note {
Subroutine note: called CC=1 SCAR=0.0
Pod documented
48 662 my $ctx = context();
49 662 $ctx->note( join '', grep { defined $_ } @_ );
50 662 $ctx->release;
51 }
52  
53 8 ▶sub todo {
Subroutine todo: called CC=4 SCAR=13.9
Pod documented
54 8 my $reason = shift;
55 8 my $code = shift;
56  
57 8 ▶ require Test2::Todo unless $INC{'Test2/Todo.pm'};
Branch: 1 branch
BranchTrueFalseTotal
unless $INC{"Test2/Todo.pm"} 6 2 8
58 8 my $todo = Test2::Todo->new(reason => $reason);
59  
60 8 ▶ return $code->() if $code;
Branch: 1 branch
BranchTrueFalseTotal
if $code 4 4 8
61  
62 4 ▶ croak "Cannot use todo() in a void context without a codeblock"
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 4 4
63 unless defined wantarray;
64  
65 4 return $todo;
66 }
67  
68 2 ▶sub skip {
Subroutine skip: called CC=3 SCAR=11.0
Pod documented
69 2 my ($why, $num) = @_;
70 2 ▶ $num ||= 1;
Condition50%1/2
$num ||= 1
l!l
20
MC/DC0%0/1
$num ||= 1
$num
Truth table50%1/2
A
A= $num
Aresult
11
00
71 2 my $ctx = context();
72 2 $ctx->skip("skipped test", $why) for 1 .. $num;
73 2 $ctx->release;
74 182 ▶ no warnings 'exiting';
Subroutine BEGIN: called CC=1 SCAR=0.0
75 2 last SKIP;
76 }
77  
78 9 ▶sub plan {
Subroutine plan: called CC=5 SCAR=16.6
Pod documented
79 9 my $plan = shift;
80 9 my $ctx = context();
81  
82 9 ▶ if ($plan && $plan =~ m/[^0-9]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plan and $plan =~ /[^0-9]/) 2 7 9
Condition66%2/3
$plan and $plan =~ /[^0-9]/
!ll&&!rl&&r
072
MC/DC50%1/2
$plan and $plan =~ /[^0-9]/
$plan $plan =~ /[^0-9]/
Truth table66%2/3
A and B
A= $planB= $plan =~ /[^0-9]/
ABresult
0X0
100
111
83 2 ▶ if ($plan eq 'tests') {
Branch: 2 branches
BranchTrueFalseTotal
if ($plan eq 'tests') { } 1 1 2
elsif ($plan eq 'skip_all') { } 1 0 1
84 1 $plan = shift;
85 }
86 elsif ($plan eq 'skip_all') {
87 1 skip_all(@_);
88 0 $ctx->release;
89 0 return;
90 }
91 }
92  
93 8 $ctx->plan($plan);
94 8 $ctx->release;
95 }
96  
97 29 ▶sub skip_all {
Subroutine skip_all: called CC=2 SCAR=7.0
Pod documented
98 29 my ($reason) = @_;
99 29 my $ctx = context();
100 29 $ctx->plan(0, SKIP => $reason);
101 2 ▶ $ctx->release if $ctx;
Branch: 1 branch
BranchTrueFalseTotal
if $ctx 2 0 2
102 }
103  
104 154 ▶sub done_testing {
Subroutine done_testing: called CC=1 SCAR=0.0
Pod documented
105 154 my $ctx = context();
106 154 $ctx->hub->finalize($ctx->trace, 1);
107 132 my $count = $ctx->hub->count;
108 132 $ctx->release;
109 132 return $count;
110 }
111  
112 3 ▶sub bail_out {
Subroutine bail_out: called CC=2 SCAR=9.2
Pod documented
113 3 my ($reason) = @_;
114 3 my $ctx = context();
115 3 $ctx->bail($reason);
116 0 ▶ $ctx->release if $ctx;
Branch: 1 branch
BranchTrueFalseTotal
if $ctx 0 0 0
117 }
118  
119 182 1;
120  
121 __END__
« blib/lib/Test2/Tools/Defer.pm ↑ Summary blib/lib/Test2/Event/Generic.pm »