Test/Exec.pm

filter: Statementstmt 100% 44 / 44 Branchbran 100% 2 / 2 Conditioncond 80.0% 4 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 12 / 12 Podpod 100% 2 / 2 totaltotal 97.0% 66 / 68 CC 4 SCAR 5.9
CC
4
Cov
98%
never_exec_ok
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.8
« Test2/Tools/Process.pm ↑ Summary
1 package Test::Exec;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Test2::API qw( context );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Test2::Tools::Process ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Return::MultiLevel qw( with_return );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # ABSTRACT: Test that some code calls exec without terminating testing
12 5 our $VERSION = '0.07'; # VERSION
13  
14  
15 5 our @EXPORT = qw( exec_arrayref never_exec_ok );
16  
17  
18 5 my $last;
19  
20 sub exec_arrayref(&)
21 10 ▶{
Subroutine exec_arrayref: called CC=1 SCAR=0.0
Pod documented
22 10 my($code) = @_;
23  
24 10 undef $last;
25  
26 10 ▶ return with_return {
Subroutine __ANON__: called CC=1 SCAR=0.0
27 10 my($return) = @_;
28 6 ▶ local $Test2::Tools::Process::handlers{exec} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
29 6 $last = [caller(1)];
30 6 $return->([@_]);
31 10 };
32 10 $code->();
33 4 undef;
34 10 };
35 }
36  
37  
38 sub never_exec_ok (&;$)
39 3 ▶{
Subroutine never_exec_ok: called CC=4 SCAR=13.9
Pod documented
40 3 my($code, $name) = @_;
41  
42 3 ▶ $name ||= 'does not call exec';
Condition100%2/2
$name ||= "does not call exec"
l!l
12
MC/DC100%1/1
$name ||= "does not call exec"
$name
Truth table100%2/2
A
A= $name
Aresult
11
00
43  
44 3 ▶ my $ret = exec_arrayref { $code->() };
Subroutine __ANON__: called CC=1 SCAR=0.0
45 3 my $ok = !defined $ret;
46  
47 3 my $ctx = context();
48 3 $ctx->ok($ok, $name);
49  
50 3 ▶ if(!$ok && $last)
Branch: 1 branch
BranchTrueFalseTotal
if (not $ok and $last) 1 2 3
Condition66%2/3
not $ok and $last
!ll&&!rl&&r
201
MC/DC50%1/2
not $ok and $last
not $ok $last
Truth table66%2/3
not(A) and B
A= not $okB= $last
ABresult
0X0
100
111
51 {
52 1 my(undef, $filename, $line) = @$last;
53 1 $ctx->diag("exec at $filename line $line");
54 }
55  
56 3 $ctx->release;
57 }
58  
59 5 1;
60  
61 __END__
« Test2/Tools/Process.pm ↑ Summary