blib/lib/Test/LeakTrace.pm

filter: Statementstmt 95.5% 65 / 68 Branchbran 68.7% 11 / 16 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 13 / 13 Podpod 100% 6 / 6 totaltotal 89.8% 97 / 108 CC 10 SCAR 10.9
CC
10
Cov
90%
leaks_cmp_ok
5.2
_do_leaktrace
5.0
leaktrace
2.0
CRAP 3.0
↑ Summary blib/lib/Test/LeakTrace/Script.pm »
1 package Test::LeakTrace;
2  
3 12 ▶use 5.008_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 12 our $VERSION = '0.17';
8  
9 12 ▶use XSLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 XSLoader::load(__PACKAGE__, $VERSION);
11  
12 12 ▶use Test::Builder::Module;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 12 our @ISA = qw(Test::Builder::Module);
14  
15 12 ▶use Exporter qw(import); # use Exporter::import for backward compatibility
Subroutine BEGIN: called CC=1 SCAR=0.0
16 12 our @EXPORT = qw(
17 leaktrace leaked_refs leaked_info leaked_count
18 no_leaks_ok leaks_cmp_ok
19 count_sv
20 );
21  
22 12 our %EXPORT_TAGS = (
23 all => \@EXPORT,
24 test => [qw(no_leaks_ok leaks_cmp_ok)],
25 util => [qw(leaktrace leaked_refs leaked_info leaked_count count_sv)],
26 );
27  
28  
29 41 ▶sub _do_leaktrace{
Subroutine _do_leaktrace: called CC=5 SCAR=16.2
30 41 my($block, $name, $need_stateinfo, $mode) = @_;
31  
32 41 ▶ if(!defined($mode) && !defined wantarray){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $mode or defined wantarray) 0 41 41
Condition66%2/3
defined $mode or defined wantarray
l!l&&r!l&&!r
9320
MC/DC0%0/2
defined $mode or defined wantarray
defined $mode defined wantarray
Truth table66%2/3
A or B
A= defined $modeB= defined wantarray
ABresult
1X1
011
000
33 0 warnings::warnif void => "Useless use of $name() in void context";
34 }
35  
36 41 ▶ if($name eq 'leaked_count') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "leaked_count") 17 24 41
37 17 my $start;
38 17 $start = count_sv();
39 17 $block->();
40 17 return count_sv() - $start;
41 }
42  
43 24 local $SIG{__DIE__} = 'DEFAULT';
44  
45 24 _start($need_stateinfo);
46 22 eval{
47 22 $block->();
48 };
49 22 ▶ if($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 2 20 22
50 2 _finish(-silent);
51 2 die $@;
52 }
53  
54 20 return _finish($mode);
55 }
56  
57 7 ▶sub leaked_refs(&){
Subroutine leaked_refs: called CC=1 SCAR=0.0
Pod documented
58 7 my($block) = @_;
59 7 return _do_leaktrace($block, 'leaked_refs', 0);
60 }
61  
62 8 ▶sub leaked_info(&){
Subroutine leaked_info: called CC=1 SCAR=0.0
Pod documented
63 8 my($block) = @_;
64 8 return _do_leaktrace($block, 'leaked_refs', 1);
65 }
66  
67 5 ▶sub leaked_count(&){
Subroutine leaked_count: called CC=1 SCAR=0.0
Pod documented
68 5 my($block) = @_;
69 5 return scalar _do_leaktrace($block, 'leaked_count', 0);
70 }
71  
72 6 ▶sub leaktrace(&;$){
Subroutine leaktrace: called CC=2 SCAR=7.1
Pod documented
73 6 my($block, $mode) = @_;
74 6 ▶ _do_leaktrace($block, 'leaktrace', 1, defined($mode) ? $mode : -simple);
Branch: 1 branch
BranchTrueFalseTotal
defined $mode ? : 6 0 6
75 2 return;
76 }
77  
78  
79 12 ▶sub leaks_cmp_ok(&$$;$){
Subroutine leaks_cmp_ok: called CC=5 SCAR=16.4
Pod documented
80 12 my($block, $cmp_op, $expected, $description) = @_;
81  
82 12 my $Test = __PACKAGE__->builder;
83  
84 12 ▶ if(!_runops_installed()){
Branch: 1 branch
BranchTrueFalseTotal
unless (_runops_installed()) 0 12 12
85 0 ▶ my $mod = exists $INC{'Devel/Cover.pm'} ? 'Devel::Cover' : 'strange runops routines';
Branch: 1 branch
BranchTrueFalseTotal
exists $INC{'Devel/Cover.pm'} ? : 0 0 0
86 0 return $Test->ok(1, "skipped (under $mod)");
87 }
88  
89 # calls to prepare cache in $block
90 12 $block->();
91  
92 12 my $got = _do_leaktrace($block, 'leaked_count', 0);
93  
94 12 my $desc = sprintf 'leaks %s %-2s %s', $got, $cmp_op, $expected;
95 12 ▶ if(defined $description){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $description) { } 3 9 12
96 3 $description .= " ($desc)";
97 }
98 else{
99 9 $description = $desc;
100 }
101  
102 12 my $result = $Test->cmp_ok($got, $cmp_op, $expected, $description);
103  
104 12 ▶ if(!$result){
Branch: 1 branch
BranchTrueFalseTotal
unless ($result) 3 9 12
105 3 open local(*STDERR), '>', \(my $content = '');
106 3 $block->(); # calls it again because opening *STDERR changes the run-time environment
107  
108 3 _do_leaktrace($block, 'leaktrace', 1, -verbose);
109 3 $Test->diag($content);
110 }
111  
112 12 return $result;
113 }
114  
115 5 ▶sub no_leaks_ok(&;$){
Subroutine no_leaks_ok: called CC=1 SCAR=0.0
Pod documented
116 # ($block, $description)
117 5 splice @_, 1, 0, ('<=', 0); # ($block, '<=', 0, $description);
118 5 goto &leaks_cmp_ok;
119 }
120  
121  
122 12 1;
123 __END__
↑ Summary blib/lib/Test/LeakTrace/Script.pm »