blib/lib/Test2/API/Context.pm

filter: Statementstmt 94.0% 235 / 250 Branchbran 84.5% 71 / 84 Conditioncond 65.6% 42 / 64 MC/DCmcdc 38.8% 14 / 36 Subroutinesub 92.3% 36 / 39 Podpod 88.0% 22 / 25 totaltotal 84.3% 420 / 498 CC 74 SCAR 23.0
CC
74
Cov
87%
DESTROY
25.1
release
19.0
init
8.2
CRAP 10.0
« blib/lib/Test2/AsyncSubtest.pm ↑ Summary blib/lib/Test2/Event/Subtest.pm »
1 package Test2::API::Context;
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 ▶use Carp qw/confess croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 455 ▶use Scalar::Util qw/weaken blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 455 ▶use Test2::Util qw/get_tid try pkg_to_file get_tid/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 455 ▶use Test2::EventFacet::Trace();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 455 ▶use Test2::API();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # Preload some key event types
16 my %LOADED = (
17 map {
18 455 my $pkg = "Test2::Event::$_";
19 5460 my $file = "Test2/Event/$_.pm";
20 5460 ▶ require $file unless $INC{$file};
Branch: 1 branch
BranchTrueFalseTotal
unless $INC{$file} 1365 4095 5460
21 5460 ( $pkg => $pkg, $_ => $pkg )
22 } qw/Ok Diag Note Plan Bail Exception Waiting Skip Subtest Pass Fail V2/
23 );
24  
25 455 ▶use Test2::Util::ExternalMeta qw/meta get_meta set_meta delete_meta/;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 455 ▶use Test2::Util::HashBase qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
27 stack hub trace _on_release _depth _is_canon _is_spawn _aborted
28 errno eval_error child_error thrown _failed _start_fail_count
29 455 };
30  
31 # Private, not package vars
32 # It is safe to cache these.
33 455 my $ON_RELEASE = Test2::API::_context_release_callbacks_ref();
34 455 my $CONTEXTS = Test2::API::_contexts_ref();
35  
36 1176 ▶sub init {
Subroutine init: called CC=8 SCAR=21.0
Pod undocumented
37 1176 my $self = shift;
38  
39 confess "The 'trace' attribute is required"
40 1176 ▶ unless $self->{+TRACE};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"trace"} 1 1175 1176
41  
42 confess "The 'hub' attribute is required"
43 1175 ▶ unless $self->{+HUB};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"hub"} 1 1174 1175
44  
45 1174 ▶ $self->{+_START_FAIL_COUNT} = $self->{+HUB}->{failed} || 0;
Condition100%2/2
$self->{'hub'}{'failed'} || 0
l!l
331141
MC/DC100%1/1
$self->{'hub'}{'failed'} || 0
$self->{'hub'}{'failed'}
Truth table100%2/2
A
A= $self->{'hub'}{'failed'}
Aresult
11
00
46  
47 1174 ▶ $self->{+_DEPTH} = 0 unless defined $self->{+_DEPTH};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_depth"} 1173 1 1174
48  
49 1174 ▶ $self->{+ERRNO} = $! unless exists $self->{+ERRNO};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"errno"} 1174 0 1174
50 1174 ▶ $self->{+EVAL_ERROR} = $@ unless exists $self->{+EVAL_ERROR};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"eval_error"} 1174 0 1174
51 1174 ▶ $self->{+CHILD_ERROR} = $? unless exists $self->{+CHILD_ERROR};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"child_error"} 1174 0 1174
52 }
53  
54 597 ▶sub snapshot { bless {%{$_[0]}, _is_canon => undef, _is_spawn => undef, _aborted => undef}, __PACKAGE__ }
Subroutine snapshot: called CC=1 SCAR=0.0
Pod documented
55  
56 0 ▶sub restore_error_vars {
Subroutine restore_error_vars: not called CC=1 SCAR=6.9
Pod documented
57 0 my $self = shift;
58 0 ($!, $@, $?) = @$self{+ERRNO, +EVAL_ERROR, +CHILD_ERROR};
59 }
60  
61 20700 ▶sub DESTROY {
Subroutine DESTROY: called CC=20 SCAR=32.2
62 20700 ▶ return unless $_[0]->{+_IS_CANON} || $_[0]->{+_IS_SPAWN};
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]{"_is_canon"} or $_[0]{"_is_spawn"} 20473 227 20700
Condition100%3/3
$_[0]{"_is_canon"} or $_[0]{"_is_spawn"}
l!l&&r!l&&!r
1656220473
MC/DC100%2/2
$_[0]{"_is_canon"} or $_[0]{"_is_spawn"}
$_[0]{"_is_canon"} $_[0]{"_is_spawn"}
Truth table100%3/3
A or B
A= $_[0]{"_is_canon"}B= $_[0]{"_is_spawn"}
ABresult
1X1
011
000
63 227 ▶ return if $_[0]->{+_ABORTED} && ${$_[0]->{+_ABORTED}};
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"_aborted"} and ${$_[0]{"_aborted"};} 123 104 227
Condition66%2/3
$_[0]{"_aborted"} and ${$_[0]{"_aborted"};}
!ll&&!rl&&r
0104123
MC/DC50%1/2
$_[0]{"_aborted"} and ${$_[0]{"_aborted"};}
$_[0]{"_aborted"} ${$_[0]{"_aborted"};}
Truth table66%2/3
A and B
A= $_[0]{"_aborted"}B= ${$_[0]{"_aborted"};}
ABresult
0X0
100
111
64 104 my ($self) = @_;
65  
66 104 my $hub = $self->{+HUB};
67 104 my $hid = $hub->{hid};
68  
69 104 ▶ $self->{+_FAILED} = ($hub->{failed} || 0) - $self->{+_START_FAIL_COUNT};
Condition50%1/2
$hub->{'failed'} || 0
l!l
0104
MC/DC0%0/1
$hub->{'failed'} || 0
$hub->{'failed'}
Truth table50%1/2
A
A= $hub->{'failed'}
Aresult
11
00
70  
71 # Do not show the warning if it looks like an exception has been thrown, or
72 # if the context is not local to this process or thread.
73 {
74 # Sometimes $@ is uninitialized, not a problem in this case so do not
75 # show the warning about using eq.
76 455 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
77 104 ▶ if($self->{+EVAL_ERROR} eq $@ && $hub->is_local && !$hub->suppress_release_error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"eval_error"} eq $@ and $hub->is_local and not $hub->suppress_release_error) 5 99 104
Condition83%5/6
$self->{"eval_error"} eq $@ and $hub->is_local and not $hub->suppress_release_error
!ll&&!rl&&r
9905
$self->{"eval_error"} eq $@ and $hub->is_local
!ll&&!rl&&r
10895
MC/DC66%2/3
$self->{"eval_error"} eq $@ and $hub->is_local and not $hub->suppress_release_error
$self->{"eval_error"} eq $@ $hub->is_local not $hub->suppress_release_error
Truth table75%3/4
A and B and not(C)
A= $self->{"eval_error"} eq $@B= $hub->is_localC= not $hub->suppress_release_error
ABCresult
0XX0
10X0
1100
1111
78 5 require Carp;
79 5 my $mess = Carp::longmess("Context destroyed");
80 5 ▶ my $frame = $self->{+_IS_SPAWN} || $self->{+TRACE}->frame;
Condition66%2/3
$self->{'_is_spawn'} || $self->{'trace'}->frame
l!l&&r!l&&!r
230
MC/DC0%0/2
$self->{'_is_spawn'} || $self->{'trace'}->frame
$self->{'_is_spawn'} $self->{'trace'}->frame
Truth table66%2/3
A || B
A= $self->{'_is_spawn'}B= $self->{'trace'}->frame
ABresult
1X1
011
000
81 5 warn <<" EOT";
82 A context appears to have been destroyed without first calling release().
83 Based on \$@ it does not look like an exception was thrown (this is not always
84 a reliable test)
85  
86 This is a problem because the global error variables (\$!, \$@, and \$?) will
87 not be restored. In addition some release callbacks will not work properly from
88 inside a DESTROY method.
89  
90 Here are the context creation details, just in case a tool forgot to call
91 release():
92 File: $frame->[1]
93 Line: $frame->[2]
94 Tool: $frame->[3]
95  
96 Here is a trace to the code that caused the context to be destroyed, this could
97 be an exit(), a goto, or simply the end of a scope:
98 $mess
99  
100 Cleaning up the CONTEXT stack...
101 EOT
102 }
103 }
104  
105 104 ▶ return if $self->{+_IS_SPAWN};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_is_spawn"} 27 77 104
106  
107 # Remove the key itself to avoid a slow memory leak
108 77 delete $CONTEXTS->{$hid};
109 77 $self->{+_IS_CANON} = undef;
110  
111 77 ▶ if (my $cbk = $self->{+_ON_RELEASE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cbk = $self->{"_on_release"}) 0 77 77
112 0 $_->($self) for reverse @$cbk;
113 }
114 77 ▶ if (my $hcbk = $hub->{_context_release}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hcbk = $hub->{"_context_release"}) 2 75 77
115 2 $_->($self) for reverse @$hcbk;
116 }
117 77 $_->($self) for reverse @$ON_RELEASE;
118  
119 77 ▶ if (my @diags = Test2::API::test2_clear_pending_diags()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@diags) = Test2::API::test2_clear_pending_diags()) 0 77 77
120 0 ▶ if ($self->{+_FAILED} || ${$self->{+_ABORTED}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_failed"} or ${$self->{"_aborted"};}) 0 0 0
Condition0%0/3
$self->{"_failed"} or ${$self->{"_aborted"};}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_failed"} or ${$self->{"_aborted"};}
$self->{"_failed"} ${$self->{"_aborted"};}
Truth table0%0/3
A or B
A= $self->{"_failed"}B= ${$self->{"_aborted"};}
ABresult
1X1
011
000
121 0 $self->diag($_) for @diags;
122 }
123 }
124 }
125  
126 # release exists to implement behaviors like die-on-fail. In die-on-fail you
127 # want to die after a failure, but only after diagnostics have been reported.
128 # The ideal time for the die to happen is when the context is released.
129 # Unfortunately die does not work in a DESTROY block.
130 18735 ▶sub release {
Subroutine release: called CC=18 SCAR=29.4
Pod documented
131 18735 my ($self) = @_;
132  
133 18735 ▶ ($!, $@, $?) = @$self{+ERRNO, +EVAL_ERROR, +CHILD_ERROR} and return if $self->{+THROWN};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"thrown"} 27 18708 18735
Condition60%3/5
$self->{'thrown'} && ((($!, $@, $?) = @$self{'errno', 'eval_error', 'child_error'}) && (return))
!ll
18708270
($!, $@, $?) = @$self{"errno", "eval_error", "child_error"} and return
!ll
027
MC/DC0%0/2
$self->{'thrown'} && ((($!, $@, $?) = @$self{'errno', 'eval_error', 'child_error'}) && (return))
$self->{'thrown'} ($!, $@, $?) = @$self{"errno", "eval_error", "child_error"}
Truth table33%1/3
A && B
A= $self->{'thrown'}B= ($!, $@, $?) = @$self{"errno", "eval_error", "child_error"}
ABresult
0X0
100
111
134  
135 ($!, $@, $?) = @$self{+ERRNO, +EVAL_ERROR, +CHILD_ERROR} and return $self->{+_IS_SPAWN} = undef
136 18708 ▶ if $self->{+_IS_SPAWN};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_is_spawn"} 5763 12945 18708
Condition60%3/5
$self->{'_is_spawn'} && ((($!, $@, $?) = @$self{'errno', 'eval_error', 'child_error'}) && (return $self->{'_is_spawn'} = undef))
!ll
1294557630
($!, $@, $?) = @$self{"errno", "eval_error", "child_error"} and return $self->{"_is_spawn"} = undef
!ll
05763
MC/DC0%0/2
$self->{'_is_spawn'} && ((($!, $@, $?) = @$self{'errno', 'eval_error', 'child_error'}) && (return $self->{'_is_spawn'} = undef))
$self->{'_is_spawn'} ($!, $@, $?) = @$self{"errno", "eval_error", "child_error"}
Truth table33%1/3
A && B
A= $self->{'_is_spawn'}B= ($!, $@, $?) = @$self{"errno", "eval_error", "child_error"}
ABresult
0X0
100
111
137  
138 croak "release() should not be called on context that is neither canon nor a child"
139 12945 ▶ unless $self->{+_IS_CANON};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_is_canon"} 1 12944 12945
140  
141 12944 my $hub = $self->{+HUB};
142 12944 my $hid = $hub->{hid};
143  
144 12944 ▶ $self->{+_FAILED} = ($hub->{failed} || 0) - $self->{+_START_FAIL_COUNT};
Condition100%2/2
$hub->{'failed'} || 0
l!l
106711877
MC/DC100%1/1
$hub->{'failed'} || 0
$hub->{'failed'}
Truth table100%2/2
A
A= $hub->{'failed'}
Aresult
11
00
145  
146 croak "context thinks it is canon, but it is not"
147 12944 ▶ unless $CONTEXTS->{$hid} && $CONTEXTS->{$hid} == $self;
Branch: 1 branch
BranchTrueFalseTotal
unless $CONTEXTS->{$hid} and $CONTEXTS->{$hid} == $self 0 12944 12944
Condition33%1/3
$CONTEXTS->{$hid} and $CONTEXTS->{$hid} == $self
!ll&&!rl&&r
0012944
MC/DC0%0/2
$CONTEXTS->{$hid} and $CONTEXTS->{$hid} == $self
$CONTEXTS->{$hid} $CONTEXTS->{$hid} == $self
Truth table33%1/3
A and B
A= $CONTEXTS->{$hid}B= $CONTEXTS->{$hid} == $self
ABresult
0X0
100
111
148  
149 # Remove the key itself to avoid a slow memory leak
150 12944 $self->{+_IS_CANON} = undef;
151 12944 delete $CONTEXTS->{$hid};
152  
153 12944 ▶ if (my $cbk = $self->{+_ON_RELEASE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cbk = $self->{"_on_release"}) 2 12942 12944
154 2 $_->($self) for reverse @$cbk;
155 }
156 12944 ▶ if (my $hcbk = $hub->{_context_release}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hcbk = $hub->{"_context_release"}) 47 12897 12944
157 47 $_->($self) for reverse @$hcbk;
158 }
159 12944 $_->($self) for reverse @$ON_RELEASE;
160  
161 12940 ▶ if (my @diags = Test2::API::test2_clear_pending_diags()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@diags) = Test2::API::test2_clear_pending_diags()) 4 12936 12940
162 4 ▶ if ($self->{+_FAILED} || ${$self->{+_ABORTED}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_failed"} or ${$self->{"_aborted"};}) 1 3 4
Condition66%2/3
$self->{"_failed"} or ${$self->{"_aborted"};}
l!l&&r!l&&!r
103
MC/DC50%1/2
$self->{"_failed"} or ${$self->{"_aborted"};}
$self->{"_failed"} ${$self->{"_aborted"};}
Truth table66%2/3
A or B
A= $self->{"_failed"}B= ${$self->{"_aborted"};}
ABresult
1X1
011
000
163 1 $self->diag($_) for @diags;
164 }
165 }
166  
167 # Do this last so that nothing else changes them.
168 # If one of the hooks dies then these do not get restored, this is
169 # intentional
170 12940 ($!, $@, $?) = @$self{+ERRNO, +EVAL_ERROR, +CHILD_ERROR};
171  
172 12940 return;
173 }
174  
175 7 ▶sub do_in_context {
Subroutine do_in_context: called CC=4 SCAR=13.9
Pod documented
176 7 my $self = shift;
177 7 my ($sub, @args) = @_;
178  
179 # We need to update the pid/tid and error vars.
180 7 my $clone = $self->snapshot;
181 7 @$clone{+ERRNO, +EVAL_ERROR, +CHILD_ERROR} = ($!, $@, $?);
182 7 $clone->{+TRACE} = $clone->{+TRACE}->snapshot(pid => $$, tid => get_tid());
183  
184 7 my $hub = $clone->{+HUB};
185 7 my $hid = $hub->hid;
186  
187 7 my $old = $CONTEXTS->{$hid};
188  
189 7 $clone->{+_IS_CANON} = 1;
190 7 $CONTEXTS->{$hid} = $clone;
191 7 weaken($CONTEXTS->{$hid});
192 7 my ($ok, $err) = &try($sub, @args);
193 7 ▶ my ($rok, $rerr) = try { $clone->release };
Subroutine __ANON__: called CC=1 SCAR=0.0
194 7 delete $clone->{+_IS_CANON};
195  
196 7 ▶ if ($old) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old) { } 1 6 7
197 1 $CONTEXTS->{$hid} = $old;
198 1 weaken($CONTEXTS->{$hid});
199 }
200 else {
201 6 delete $CONTEXTS->{$hid};
202 }
203  
204 7 ▶ die $err unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 6 7
205 6 ▶ die $rerr unless $rok;
Branch: 1 branch
BranchTrueFalseTotal
unless $rok 0 6 6
206 }
207  
208 89 ▶sub done_testing {
Subroutine done_testing: called CC=1 SCAR=0.0
Pod documented
209 89 my $self = shift;
210 89 $self->hub->finalize($self->trace, 1);
211 89 return;
212 }
213  
214 25 ▶sub throw {
Subroutine throw: called CC=4 SCAR=13.9
Pod documented
215 25 my ($self, $msg) = @_;
216 25 $self->{+THROWN} = 1;
217 25 ▶ ${$self->{+_ABORTED}}++ if $self->{+_ABORTED};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_aborted"} 25 0 25
218 25 ▶ $self->release if $self->{+_IS_CANON} || $self->{+_IS_SPAWN};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_is_canon"} or $self->{"_is_spawn"} 23 2 25
Condition100%3/3
$self->{"_is_canon"} or $self->{"_is_spawn"}
l!l&&r!l&&!r
1672
MC/DC100%2/2
$self->{"_is_canon"} or $self->{"_is_spawn"}
$self->{"_is_canon"} $self->{"_is_spawn"}
Truth table100%3/3
A or B
A= $self->{"_is_canon"}B= $self->{"_is_spawn"}
ABresult
1X1
011
000
219 25 $self->trace->throw($msg);
220 }
221  
222 4 ▶sub alert {
Subroutine alert: called CC=1 SCAR=0.0
Pod documented
223 4 my ($self, $msg) = @_;
224 4 $self->trace->alert($msg);
225 }
226  
227 0 ▶sub send_ev2_and_release {
Subroutine send_ev2_and_release: not called CC=1 SCAR=6.9
Pod documented
228 0 my $self = shift;
229 0 my $out = $self->send_ev2(@_);
230 0 $self->release;
231 0 return $out;
232 }
233  
234 361 ▶sub send_ev2 {
Subroutine send_ev2: called CC=5 SCAR=17.4
Pod documented
235 361 my $self = shift;
236  
237 361 my $e;
238 {
239 361 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
240 $e = Test2::Event::V2->new(
241 361 trace => $self->{+TRACE}->snapshot,
242 @_,
243 );
244 }
245  
246 361 ▶ if ($self->{+_ABORTED}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_aborted"}) 4 357 361
247 4 my $f = $e->facet_data;
248 0 ▶ ${$self->{+_ABORTED}}++ if $f->{control}->{halt} || defined($f->{control}->{terminate}) || defined($e->terminate);
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"control"}{"halt"} or defined $f->{"control"}{"terminate"} or defined $e->terminate 0 4 4
Condition33%2/6
$f->{"control"}{"halt"} or defined $f->{"control"}{"terminate"} or defined $e->terminate
l!l&&r!l&&!r
004
$f->{"control"}{"halt"} or defined $f->{"control"}{"terminate"}
l!l&&r!l&&!r
004
MC/DC0%0/3
$f->{"control"}{"halt"} or defined $f->{"control"}{"terminate"} or defined $e->terminate
$f->{"control"}{"halt"} defined $f->{"control"}{"terminate"} defined $e->terminate
Truth table25%1/4
A or B or C
A= $f->{"control"}{"halt"}B= defined $f->{"control"}{"terminate"}C= defined $e->terminate
ABCresult
1XX1
01X1
0011
0000
249 }
250 361 $self->{+HUB}->send($e);
251 }
252  
253 3 ▶sub build_ev2 {
Subroutine build_ev2: called CC=1 SCAR=0.0
Pod undocumented
254 3 my $self = shift;
255  
256 3 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
257 Test2::Event::V2->new(
258 3 trace => $self->{+TRACE}->snapshot,
259 @_,
260 );
261 }
262  
263 0 ▶sub send_event_and_release {
Subroutine send_event_and_release: not called CC=1 SCAR=6.9
Pod documented
264 0 my $self = shift;
265 0 my $out = $self->send_event(@_);
266 0 $self->release;
267 0 return $out;
268 }
269  
270 2222 ▶sub send_event {
Subroutine send_event: called CC=6 SCAR=17.9
Pod documented
271 2222 my $self = shift;
272 2222 my $event = shift;
273 2222 my %args = @_;
274  
275 2222 ▶ my $pkg = $LOADED{$event} || $self->_parse_event($event);
Condition66%2/3
$LOADED{$event} || $self->_parse_event($event)
l!l&&r!l&&!r
221930
MC/DC0%0/2
$LOADED{$event} || $self->_parse_event($event)
$LOADED{$event} $self->_parse_event($event)
Truth table66%2/3
A || B
A= $LOADED{$event}B= $self->_parse_event($event)
ABresult
1X1
011
000
276  
277 2222 my $e;
278 {
279 2222 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
280 $e = $pkg->new(
281 2222 trace => $self->{+TRACE}->snapshot,
282 %args,
283 );
284 }
285  
286 2222 ▶ if ($self->{+_ABORTED}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_aborted"}) 2092 130 2222
287 2092 my $f = $e->facet_data;
288 2092 ▶ ${$self->{+_ABORTED}}++ if $f->{control}->{halt} || defined($f->{control}->{terminate}) || defined($e->terminate);
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"control"}{"halt"} or defined $f->{"control"}{"terminate"} or defined $e->terminate 70 2022 2092
Condition83%5/6
$f->{"control"}{"halt"} or defined $f->{"control"}{"terminate"} or defined $e->terminate
l!l&&r!l&&!r
7002022
$f->{"control"}{"halt"} or defined $f->{"control"}{"terminate"}
l!l&&r!l&&!r
15552022
MC/DC66%2/3
$f->{"control"}{"halt"} or defined $f->{"control"}{"terminate"} or defined $e->terminate
$f->{"control"}{"halt"} defined $f->{"control"}{"terminate"} defined $e->terminate
Truth table75%3/4
A or B or C
A= $f->{"control"}{"halt"}B= defined $f->{"control"}{"terminate"}C= defined $e->terminate
ABCresult
1XX1
01X1
0011
0000
289 }
290 2222 $self->{+HUB}->send($e);
291 }
292  
293 732 ▶sub build_event {
Subroutine build_event: called CC=2 SCAR=7.1
Pod documented
294 732 my $self = shift;
295 732 my $event = shift;
296 732 my %args = @_;
297  
298 732 ▶ my $pkg = $LOADED{$event} || $self->_parse_event($event);
Condition33%1/3
$LOADED{$event} || $self->_parse_event($event)
l!l&&r!l&&!r
73200
MC/DC0%0/2
$LOADED{$event} || $self->_parse_event($event)
$LOADED{$event} $self->_parse_event($event)
Truth table33%1/3
A || B
A= $LOADED{$event}B= $self->_parse_event($event)
ABresult
1X1
011
000
299  
300 732 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
301 $pkg->new(
302 732 trace => $self->{+TRACE}->snapshot,
303 %args,
304 );
305 }
306  
307 2 ▶sub pass {
Subroutine pass: called CC=1 SCAR=0.0
Pod documented
308 2 my $self = shift;
309 2 my ($name) = @_;
310  
311 my $e = bless(
312 {
313 2 trace => bless({%{$self->{+TRACE}}}, 'Test2::EventFacet::Trace'),
314 name => $name,
315 },
316 "Test2::Event::Pass"
317 );
318  
319 2 $self->{+HUB}->send($e);
320 2 return $e;
321 }
322  
323 1948 ▶sub pass_and_release {
Subroutine pass_and_release: called CC=1 SCAR=0.0
Pod documented
324 1948 my $self = shift;
325 1948 my ($name) = @_;
326  
327 my $e = bless(
328 {
329 1948 trace => bless({%{$self->{+TRACE}}}, 'Test2::EventFacet::Trace'),
330 name => $name,
331 },
332 "Test2::Event::Pass"
333 );
334  
335 1948 $self->{+HUB}->send($e);
336 1948 $self->release;
337 1948 return 1;
338 }
339  
340 230 ▶sub fail {
Subroutine fail: called CC=3 SCAR=11.0
Pod documented
341 230 my $self = shift;
342 230 my ($name, @diag) = @_;
343  
344 my $e = bless(
345 {
346 230 trace => bless({%{$self->{+TRACE}}}, 'Test2::EventFacet::Trace'),
347 name => $name,
348 },
349 "Test2::Event::Fail"
350 );
351  
352 230 for my $msg (@diag) {
353 234 ▶ if (ref($msg) eq 'Test2::EventFacet::Info::Table') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $msg eq 'Test2::EventFacet::Info::Table') { } 229 5 234
354 229 $e->add_info({tag => 'DIAG', debug => 1, $msg->info_args});
355 }
356 else {
357 5 $e->add_info({tag => 'DIAG', debug => 1, details => $msg});
358 }
359 }
360  
361 230 $self->{+HUB}->send($e);
362 230 return $e;
363 }
364  
365 27 ▶sub fail_and_release {
Subroutine fail_and_release: called CC=3 SCAR=11.0
Pod documented
366 27 my $self = shift;
367 27 my ($name, @diag) = @_;
368  
369 my $e = bless(
370 {
371 27 trace => bless({%{$self->{+TRACE}}}, 'Test2::EventFacet::Trace'),
372 name => $name,
373 },
374 "Test2::Event::Fail"
375 );
376  
377 27 for my $msg (@diag) {
378 21 ▶ if (ref($msg) eq 'Test2::EventFacet::Info::Table') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $msg eq 'Test2::EventFacet::Info::Table') { } 1 20 21
379 1 $e->add_info({tag => 'DIAG', debug => 1, $msg->info_args});
380 }
381 else {
382 20 $e->add_info({tag => 'DIAG', debug => 1, details => $msg});
383 }
384 }
385  
386 27 $self->{+HUB}->send($e);
387 27 $self->release;
388 27 return 0;
389 }
390  
391 2570 ▶sub ok {
Subroutine ok: called CC=5 SCAR=16.1
Pod documented
392 2570 my $self = shift;
393 2570 my ($pass, $name, $on_fail) = @_;
394  
395 2570 my $hub = $self->{+HUB};
396  
397 my $e = bless {
398 2570 trace => bless( {%{$self->{+TRACE}}}, 'Test2::EventFacet::Trace'),
399 pass => $pass,
400 name => $name,
401 }, 'Test2::Event::Ok';
402 2570 $e->init;
403  
404 2570 $hub->send($e);
405 2570 ▶ return $e if $pass;
Branch: 1 branch
BranchTrueFalseTotal
if $pass 2482 88 2570
406  
407 88 $self->failure_diag($e);
408  
409 88 ▶ if ($on_fail && @$on_fail) {
Branch: 1 branch
BranchTrueFalseTotal
if ($on_fail and @$on_fail) 48 40 88
Condition100%3/3
$on_fail and @$on_fail
!ll&&!rl&&r
83248
MC/DC100%2/2
$on_fail and @$on_fail
$on_fail @$on_fail
Truth table100%3/3
A and B
A= $on_failB= @$on_fail
ABresult
0X0
100
111
410 48 $self->diag($_) for @$on_fail;
411 }
412  
413 88 return $e;
414 }
415  
416 109 ▶sub failure_diag {
Subroutine failure_diag: called CC=3 SCAR=11.0
Pod undocumented
417 109 my $self = shift;
418 109 my ($e) = @_;
419  
420 # Figure out the debug info, this is typically the file name and line
421 # number, but can also be a custom message. If no trace object is provided
422 # then we have nothing useful to display.
423 109 my $name = $e->name;
424 109 my $trace = $e->trace;
425 109 ▶ my $debug = $trace ? $trace->debug : "[No trace info available]";
Branch: 1 branch
BranchTrueFalseTotal
$trace ? : 109 0 109
426  
427 # Create the initial diagnostics. If the test has a name we put the debug
428 # info on a second line, this behavior is inherited from Test::Builder.
429 109 ▶ my $msg = defined($name)
Branch: 1 branch
BranchTrueFalseTotal
defined $name ? : 94 15 109
430 ? qq[Failed test '$name'\n$debug.\n]
431 : qq[Failed test $debug.\n];
432  
433 109 $self->diag($msg);
434 }
435  
436 43 ▶sub skip {
Subroutine skip: called CC=1 SCAR=0.0
Pod documented
437 43 my $self = shift;
438 43 my ($name, $reason, @extra) = @_;
439 43 $self->send_event(
440 'Skip',
441 name => $name,
442 reason => $reason,
443 pass => 1,
444 @extra,
445 );
446 }
447  
448 876 ▶sub note {
Subroutine note: called CC=1 SCAR=0.0
Pod documented
449 876 my $self = shift;
450 876 my ($message) = @_;
451 876 $self->send_event('Note', message => $message);
452 }
453  
454 986 ▶sub diag {
Subroutine diag: called CC=1 SCAR=0.0
Pod documented
455 986 my $self = shift;
456 986 my ($message) = @_;
457 986 $self->send_event(
458 'Diag',
459 message => $message,
460 );
461 }
462  
463 283 ▶sub plan {
Subroutine plan: called CC=1 SCAR=0.0
Pod documented
464 283 my ($self, $max, $directive, $reason) = @_;
465 283 $self->send_event('Plan', max => $max, directive => $directive, reason => $reason);
466 }
467  
468 15 ▶sub bail {
Subroutine bail: called CC=1 SCAR=0.0
Pod documented
469 15 my ($self, $reason) = @_;
470 15 $self->send_event('Bail', reason => $reason);
471 }
472  
473 6 ▶sub _parse_event {
Subroutine _parse_event: called CC=5 SCAR=16.1
474 6 my $self = shift;
475 6 my $event = shift;
476  
477 6 my $pkg;
478 6 ▶ if ($event =~ m/^\+(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($event =~ /^\+(.*)/) { } 3 3 6
479 3 $pkg = $1;
480 }
481 else {
482 3 $pkg = "Test2::Event::$event";
483 }
484  
485 6 ▶ unless ($LOADED{$pkg}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($LOADED{$pkg}) 4 2 6
486 4 my $file = pkg_to_file($pkg);
487 4 ▶ my ($ok, $err) = try { require $file };
Subroutine __ANON__: called CC=1 SCAR=0.0
488 4 ▶ $self->throw("Could not load event module '$pkg': $err")
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 3 4
489 unless $ok;
490  
491 3 $LOADED{$pkg} = $pkg;
492 }
493  
494 5 ▶ confess "'$pkg' is not a subclass of 'Test2::Event'"
Branch: 1 branch
BranchTrueFalseTotal
unless $pkg->isa("Test2::Event") 0 5 5
495 unless $pkg->isa('Test2::Event');
496  
497 5 $LOADED{$event} = $pkg;
498  
499 5 return $pkg;
500 }
501  
502 455 1;
503  
504 __END__
« blib/lib/Test2/AsyncSubtest.pm ↑ Summary blib/lib/Test2/Event/Subtest.pm »