blib/lib/DBIO/Test/Util/LeakTracer.pm

filter: Statementstmt 29.4% 53 / 180 Branchbran 6.1% 5 / 82 Conditioncond 12.0% 7 / 58 MC/DCmcdc 0.0% 0 / 33 Subroutinesub 59.0% 13 / 22 Podpod 0.0% 0 / 4 totaltotal 20.5% 78 / 379 CC 72 SCAR 52.9
CC
72
Cov
20%
assert_empty_weakregistry
552.0
visit_refs
240.0
populate_weakregistry
110.0
CRAP 198.2
« blib/lib/DBIO/ResultSource.pm ↑ Summary blib/lib/DBIO/Test/Schema.pm »
1 package DBIO::Test::Util::LeakTracer;
2 # ABSTRACT: Memory leak detection and tracing for DBIO tests
3  
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '0.900007';
7  
8 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Scalar::Util qw(isweak weaken blessed reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use DBIO::Util qw(refcount hrefaddr refdesc);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use DBIO::Optional::Dependencies;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Data::Dumper 'Dumper';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use DBIO::Test::Util qw( stacktrace visit_namespaces );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use constant {
Subroutine BEGIN: called CC=3 SCAR=13.3
18 CV_TRACING => (
19 !( !$ENV{AUTOMATED_TESTING} && !$ENV{RELEASE_TESTING} )
20 2 ▶ &&
Condition33%2/6
!!($ENV{'AUTOMATED_TESTING'} || $ENV{'RELEASE_TESTING'}) && 'DBIO::Optional::Dependencies'->req_ok_for('test_leaks_heavy')
!ll&&!rl&&r
020
$ENV{'AUTOMATED_TESTING'} || $ENV{'RELEASE_TESTING'}
l!l&&r!l&&!r
200
MC/DC0%0/3
!!($ENV{'AUTOMATED_TESTING'} || $ENV{'RELEASE_TESTING'}) && 'DBIO::Optional::Dependencies'->req_ok_for('test_leaks_heavy')
$ENV{'AUTOMATED_TESTING'} $ENV{'RELEASE_TESTING'} 'DBIO::Optional::Dependencies'->req_ok_for('test_leaks_heavy')
Truth table20%1/5
A || B && C
A= $ENV{'AUTOMATED_TESTING'}B= $ENV{'RELEASE_TESTING'}C= 'DBIO::Optional::Dependencies'->req_ok_for('test_leaks_heavy')
ABCresult
00X0
1X00
0100
1X11
0111
21 DBIO::Optional::Dependencies->req_ok_for('test_leaks_heavy')
22 ),
23 SKIP_SCALAR_REFS => ( "$]" < 5.008004 ),
24 2 };
25  
26 2 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 our @EXPORT_OK = qw(populate_weakregistry assert_empty_weakregistry visit_refs);
28  
29 2 my $refs_traced = 0;
30 2 my $leaks_found = 0;
31 2 my %reg_of_regs;
32  
33 0 ▶sub populate_weakregistry {
Subroutine populate_weakregistry: not called CC=10 SCAR=47.0
Pod undocumented
34 0 my ($weak_registry, $target, $note) = @_;
35  
36 0 ▶ croak 'Expecting a registry hashref' unless ref $weak_registry eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $weak_registry eq "HASH" 0 0 0
37 0 ▶ croak 'Target is not a reference' unless length ref $target;
Branch: 1 branch
BranchTrueFalseTotal
unless length ref $target 0 0 0
38  
39 0 my $refaddr = hrefaddr $target;
40  
41 # a registry could be fed to itself or another registry via recursive sweeps
42 0 ▶ return $target if $reg_of_regs{$refaddr};
Branch: 1 branch
BranchTrueFalseTotal
if $reg_of_regs{$refaddr} 0 0 0
43  
44 0 return $target if SKIP_SCALAR_REFS and reftype($target) eq 'SCALAR';
45  
46 weaken( $reg_of_regs{ hrefaddr($weak_registry) } = $weak_registry )
47 0 ▶ unless( $reg_of_regs{ hrefaddr($weak_registry) } );
Branch: 1 branch
BranchTrueFalseTotal
unless $reg_of_regs{&hrefaddr($weak_registry)} 0 0 0
48  
49 # an explicit "garbage collection" pass every time we store a ref
50 # if we do not do this the registry will keep growing appearing
51 # as if the traced program is continuously slowly leaking memory
52 0 for my $reg (values %reg_of_regs) {
53 (defined $reg->{$_}{weakref}) or delete $reg->{$_}
54 0 ▶ for keys %$reg;
Branch: 1 branch
BranchTrueFalseTotal
defined $reg->{$_}{"weakref"} or delete $reg->{$_} 0 0 0
55 }
56  
57 0 ▶ if (! defined $weak_registry->{$refaddr}{weakref}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $weak_registry->{$refaddr}{"weakref"}) 0 0 0
58 0 $weak_registry->{$refaddr} = {
59 stacktrace => stacktrace(1),
60 weakref => $target,
61 };
62 0 weaken( $weak_registry->{$refaddr}{weakref} );
63 0 $refs_traced++;
64 }
65  
66 0 my $desc = refdesc $target;
67 0 $weak_registry->{$refaddr}{slot_names}{$desc} = 1;
68 0 ▶ if ($note) {
Branch: 1 branch
BranchTrueFalseTotal
if ($note) 0 0 0
69 0 $note =~ s/\s*\Q$desc\E\s*//g;
70 0 $weak_registry->{$refaddr}{slot_names}{$note} = 1;
71 }
72  
73 0 $target;
74 }
75  
76 # Regenerate the slots names on a thread spawn
77 0 ▶sub CLONE {
Subroutine CLONE: not called CC=5 SCAR=34.0
78 0 ▶ my @individual_regs = grep { scalar keys %{$_||{}} } values %reg_of_regs;
Condition0%0/2
$_ || {}
l!l
00
MC/DC0%0/1
$_ || {}
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
79 0 %reg_of_regs = ();
80  
81 0 for my $reg (@individual_regs) {
82 0 ▶ my @live_slots = grep { defined $_->{weakref} } values %$reg
Branch: 1 branch
BranchTrueFalseTotal
my(@live_slots) = grep({defined $_->{"weakref"};} values %$reg) or next 0 0 0
83 or next;
84  
85 0 $reg = {}; # get a fresh hashref in the new thread ctx
86 0 weaken( $reg_of_regs{hrefaddr($reg)} = $reg );
87  
88 0 for my $slot_info (@live_slots) {
89 0 my $new_addr = hrefaddr $slot_info->{weakref};
90  
91 # replace all slot names
92 $slot_info->{slot_names} = { map {
93 0 my $name = $_;
94 0 $name =~ s/\(0x[0-9A-F]+\)/sprintf ('(%s)', $new_addr)/ieg;
95 0 ($name => 1);
96 0 } keys %{$slot_info->{slot_names}} };
97  
98 0 $reg->{$new_addr} = $slot_info;
99 }
100 }
101 }
102  
103 0 ▶sub visit_refs {
Subroutine visit_refs: not called CC=15 SCAR=54.8
Pod undocumented
104 0 ▶ my $args = { (ref $_[0]) ? %{$_[0]} : @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
105  
106 0 ▶ $args->{seen_refs} ||= {};
Condition0%0/2
$args->{"seen_refs"} ||= {}
l!l
00
MC/DC0%0/1
$args->{"seen_refs"} ||= {}
$args->{"seen_refs"}
Truth table0%0/2
A
A= $args->{"seen_refs"}
Aresult
11
00
107  
108 0 my $visited_cnt = '0E0';
109 0 for my $i (0 .. $#{$args->{refs}} ) {
110  
111 0 ▶ next unless length ref $args->{refs}[$i]; # not-a-ref
Branch: 1 branch
BranchTrueFalseTotal
unless length ref $args->{"refs"}[$i] 0 0 0
112  
113 0 my $addr = hrefaddr $args->{refs}[$i];
114  
115 # no diving into weakregistries
116 0 ▶ next if $reg_of_regs{$addr};
Branch: 1 branch
BranchTrueFalseTotal
if $reg_of_regs{$addr} 0 0 0
117  
118 0 ▶ next if $args->{seen_refs}{$addr}++;
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"seen_refs"}{$addr}++ 0 0 0
119 0 $visited_cnt++;
120  
121 0 my $r = $args->{refs}[$i];
122  
123 0 ▶ $args->{action}->($r) or next;
Branch: 1 branch
BranchTrueFalseTotal
$args->{"action"}->($r) or next 0 0 0
124  
125 # This may end up being necessarry some day, but do not slow things
126 # down for now
127 #if ( defined( my $t = tied($r) ) ) {
128 # $visited_cnt += visit_refs({ %$args, refs => [ $t ] });
129 #}
130  
131 0 my $type = reftype $r;
132  
133 0 local $@;
134 0 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { if ($type eq "HASH") { $visited_cnt += visit_refs({%$args, "refs", [map({!builtin::is_weak($r->{$_}) ? $r->{$_} : ();} keys %$r)]}); } elsif ($type eq "ARRAY") { $visited_cnt += visit_refs({%$args, "refs", [map({!builtin::is_weak($r->[$_]) ? $r->[$_] : ();} 0 .. $r->$#*)]}); } elsif ($type eq "REF" and not builtin::is_weak($$r)) { $visited_cnt += visit_refs({%$args, "refs", [$$r]}); } else { '???'; } ; 1 } } or warn "Could not descend into @{[&refdesc($r)];}: $@\n" 0 0 0
135 0 ▶ if ($type eq 'HASH') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'HASH') { } 0 0 0
elsif ($type eq 'ARRAY') { } 0 0 0
elsif ($type eq 'REF' and not builtin::is_weak($$r)) { } 0 0 0
136 $visited_cnt += visit_refs({ %$args, refs => [ map {
137 0 ▶ ( !isweak($r->{$_}) ) ? $r->{$_} : ()
Branch: 1 branch
BranchTrueFalseTotal
!builtin::is_weak($r->{$_}) ? : 0 0 0
138 } keys %$r ] });
139 }
140 elsif ($type eq 'ARRAY') {
141 $visited_cnt += visit_refs({ %$args, refs => [ map {
142 0 ▶ ( !isweak($r->[$_]) ) ? $r->[$_] : ()
Branch: 1 branch
BranchTrueFalseTotal
!builtin::is_weak($r->[$_]) ? : 0 0 0
143 } 0..$#$r ] });
144 }
145 ▶ elsif ($type eq 'REF' and !isweak($$r)) {
Condition0%0/3
$type eq "REF" and not builtin::is_weak($$r)
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "REF" and not builtin::is_weak($$r)
$type eq "REF" not builtin::is_weak($$r)
Truth table0%0/3
A and not(B)
A= $type eq "REF"B= not builtin::is_weak($$r)
ABresult
0X0
100
111
146 0 $visited_cnt += visit_refs({ %$args, refs => [ $$r ] });
147 }
148 elsif (CV_TRACING and $type eq 'CODE') {
149 $visited_cnt += visit_refs({ %$args, refs => [ map {
150 ( !isweak($_) ) ? $_ : ()
151 } values %{ scalar PadWalker::closed_over($r) } ] }); # scalar due to RT#92269
152 }
153 0 1;
154 0 } or warn "Could not descend into @{[ refdesc $r ]}: $@\n";
155 }
156 0 $visited_cnt;
157 }
158  
159 # compiles a list of addresses stored as globals (possibly even catching
160 # class data in the form of method closures), so we can skip them further on
161 0 ▶sub symtable_referenced_addresses {
Subroutine symtable_referenced_addresses: not called CC=1 SCAR=5.7
Pod undocumented
162  
163 0 my $refs_per_pkg;
164  
165 0 my $seen_refs = {};
166 visit_namespaces(
167 0 ▶ action => sub {
Subroutine __ANON__: not called CC=7 SCAR=37.7
168  
169 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
170  
171 0 my $pkg = shift;
172  
173 # the unless regex at the end skips some dangerous namespaces outright
174 # (but does not prevent descent)
175 $refs_per_pkg->{$pkg} += visit_refs (
176 seen_refs => $seen_refs,
177  
178 0 ▶ action => sub { 1 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
179  
180 0 refs => [ map { my $sym = $_;
181 # *{"${pkg}::$sym"}{CODE} won't simply work - MRO-cached CVs are invisible there
182 ( CV_TRACING ? Class::MethodCache::get_cv("${pkg}::$sym") : () ),
183  
184 0 ( defined *{"${pkg}::$sym"}{SCALAR} and length ref ${"${pkg}::$sym"} and ! isweak( ${"${pkg}::$sym"} ) )
185 0 ? ${"${pkg}::$sym"} : ()
186 ,
187  
188 ( map {
189 0 ▶ ( defined *{"${pkg}::$sym"}{$_} and ! isweak(defined *{"${pkg}::$sym"}{$_}) )
Branch: 1 branch
BranchTrueFalseTotal
defined *{"${pkg}::$sym";}{'SCALAR'} && length ref ${"${pkg}::$sym";} && !builtin::is_weak(${"${pkg}::$sym";}) ? : 0 0 0
Condition0%0/6
defined *{"${pkg}::$sym";}{"SCALAR"} and length ref ${"${pkg}::$sym";} and not builtin::is_weak(${"${pkg}::$sym";})
!ll&&!rl&&r
000
defined *{"${pkg}::$sym";}{"SCALAR"} and length ref ${"${pkg}::$sym";}
!ll&&!rl&&r
000
MC/DC0%0/3
defined *{"${pkg}::$sym";}{"SCALAR"} and length ref ${"${pkg}::$sym";} and not builtin::is_weak(${"${pkg}::$sym";})
defined *{"${pkg}::$sym";}{"SCALAR"} length ref ${"${pkg}::$sym";} not builtin::is_weak(${"${pkg}::$sym";})
Truth table0%0/4
A and B and not(C)
A= defined *{"${pkg}::$sym";}{"SCALAR"}B= length ref ${"${pkg}::$sym";}C= not builtin::is_weak(${"${pkg}::$sym";})
ABCresult
0XX0
10X0
1100
1111
190 0 ▶ ? *{"${pkg}::$sym"}{$_}
Branch: 1 branch
BranchTrueFalseTotal
defined *{"${pkg}::$sym";}{$_} && !builtin::is_weak(defined *{"${pkg}::$sym";}{$_}) ? : 0 0 0
Condition0%0/3
defined *{"${pkg}::$sym";}{$_} and not builtin::is_weak(defined *{"${pkg}::$sym";}{$_})
!ll&&!rl&&r
000
MC/DC0%0/2
defined *{"${pkg}::$sym";}{$_} and not builtin::is_weak(defined *{"${pkg}::$sym";}{$_})
defined *{"${pkg}::$sym";}{$_} not builtin::is_weak(defined *{"${pkg}::$sym";}{$_})
Truth table0%0/3
A and not(B)
A= defined *{"${pkg}::$sym";}{$_}B= not builtin::is_weak(defined *{"${pkg}::$sym";}{$_})
ABresult
0X0
100
111
191 : ()
192 } qw(HASH ARRAY IO GLOB) ),
193  
194 0 ▶ } keys %{"${pkg}::"} ],
Branch: 1 branch
BranchTrueFalseTotal
unless $pkg =~ /^ (?: DB | next | B | .+? ::::ISA (?: ::CACHE ) | Class::C3 | B::Hooks::EndOfScope::PP::HintHash::.+ ) $/x 0 0 0
195 ) unless $pkg =~ /^ (?:
196 DB | next | B | .+? ::::ISA (?: ::CACHE ) | Class::C3 | B::Hooks::EndOfScope::PP::HintHash::.+
197 ) $/x;
198 }
199 0 );
200  
201 # use Devel::Dwarn;
202 # Ddie [ map
203 # { { $_ => $refs_per_pkg->{$_} } }
204 # sort
205 # {$refs_per_pkg->{$a} <=> $refs_per_pkg->{$b} }
206 # keys %$refs_per_pkg
207 # ];
208  
209 0 $seen_refs;
210 }
211  
212 0 ▶sub assert_empty_weakregistry {
Subroutine assert_empty_weakregistry: not called CC=23 SCAR=63.1
Pod undocumented
213 0 my ($weak_registry, $quiet) = @_;
214  
215 # in case we hooked bless any extra object creation will wreak
216 # havoc during the assert phase
217 0 local *CORE::GLOBAL::bless;
218 0 ▶ *CORE::GLOBAL::bless = sub { CORE::bless( $_[0], (@_ > 1) ? $_[1] : caller() ) };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 0 0 0
219  
220 0 ▶ croak 'Expecting a registry hashref' unless ref $weak_registry eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $weak_registry eq "HASH" 0 0 0
221  
222 defined $weak_registry->{$_}{weakref} or delete $weak_registry->{$_}
223 0 ▶ for keys %$weak_registry;
Branch: 1 branch
BranchTrueFalseTotal
defined $weak_registry->{$_}{"weakref"} or delete $weak_registry->{$_} 0 0 0
224  
225 0 ▶ return unless keys %$weak_registry;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$weak_registry 0 0 0
226  
227 0 ▶ my $tb = eval { Test::Builder->new }
Branch: 1 branch
BranchTrueFalseTotal
my $tb = eval { do { "Test::Builder"->new } } or croak("Calling assert_empty_weakregistry in $0 without a loaded Test::Builder makes no sense") 0 0 0
228 or croak "Calling assert_empty_weakregistry in $0 without a loaded Test::Builder makes no sense";
229  
230 0 for my $addr (keys %$weak_registry) {
231 $weak_registry->{$addr}{display_name} = join ' | ', (
232 sort
233 0 ▶ { length $a <=> length $b or $a cmp $b }
Condition0%0/3
length $a <=> length $b || $a cmp $b
l!l&&r!l&&!r
000
MC/DC0%0/2
length $a <=> length $b || $a cmp $b
length $a <=> length $b $a cmp $b
Truth table0%0/3
A || B
A= length $a <=> length $bB= $a cmp $b
ABresult
1X1
011
000
234 0 keys %{$weak_registry->{$addr}{slot_names}}
235 );
236  
237 $tb->BAILOUT("!!!! WEAK REGISTRY SLOT $weak_registry->{$addr}{display_name} IS NOT A WEAKREF !!!!")
238 0 ▶ if defined $weak_registry->{$addr}{weakref} and ! isweak( $weak_registry->{$addr}{weakref} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $weak_registry->{$addr}{"weakref"} and not builtin::is_weak($weak_registry->{$addr}{"weakref"}) 0 0 0
Condition0%0/3
defined $weak_registry->{$addr}{"weakref"} and not builtin::is_weak($weak_registry->{$addr}{"weakref"})
!ll&&!rl&&r
000
MC/DC0%0/2
defined $weak_registry->{$addr}{"weakref"} and not builtin::is_weak($weak_registry->{$addr}{"weakref"})
defined $weak_registry->{$addr}{"weakref"} not builtin::is_weak($weak_registry->{$addr}{"weakref"})
Truth table0%0/3
A and not(B)
A= defined $weak_registry->{$addr}{"weakref"}B= not builtin::is_weak($weak_registry->{$addr}{"weakref"})
ABresult
0X0
100
111
239 }
240  
241 # the symtable walk is very expensive
242 # if we are $quiet (running in an END block) we do not really need to be
243 # that thorough - can get by with only %Sub::Quote::QUOTED
244 0 ▶ delete $weak_registry->{$_} for $quiet
Branch: 1 branch
BranchTrueFalseTotal
$quiet ? : 0 0 0
245 ? do {
246 0 my $refs = {};
247 visit_refs (
248 # only look at the closed over stuffs
249 0 refs => [ grep { length ref $_ } (
250  
251 # old style Sub::Quote
252 0 ( map { values %{ $_->[2]} } grep { ref $_ eq 'ARRAY' } values %Sub::Quote::QUOTED ),
253  
254 # new style Sub::Quote
255 0 ( map { values %{ $_->{captures}} } grep { ref $_ eq 'HASH' } values %Sub::Quote::QUOTED ),
256  
257 )],
258 seen_refs => $refs,
259 0 ▶ action => sub { 1 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
260 0 );
261 0 keys %$refs;
262 }
263 : (
264 # full sumtable walk, starting from ::
265 0 keys %{ symtable_referenced_addresses() }
266 )
267 ;
268  
269 0 for my $addr (sort { $weak_registry->{$a}{display_name} cmp $weak_registry->{$b}{display_name} } keys %$weak_registry) {
270  
271 0 ▶ next if ! defined $weak_registry->{$addr}{weakref};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $weak_registry->{$addr}{"weakref"} 0 0 0
272  
273 0 ▶ $leaks_found++ unless $tb->in_todo;
Branch: 1 branch
BranchTrueFalseTotal
unless $tb->in_todo 0 0 0
274 0 $tb->ok (0, "Expected garbage collection of $weak_registry->{$addr}{display_name}");
275  
276 0 my $diag = do {
277 0 local $Data::Dumper::Indent = 1;
278 0 local $Data::Dumper::Terse = 1;
279 0 local $Data::Dumper::Sortkeys = 1;
280 0 local $Data::Dumper::Maxdepth = 1;
281 sprintf "\n%s (refcnt %d) => %s\n",
282 $weak_registry->{$addr}{display_name},
283 refcount($weak_registry->{$addr}{weakref}),
284 (
285 ref($weak_registry->{$addr}{weakref}) eq 'CODE'
286 and
287 B::svref_2object($weak_registry->{$addr}{weakref})->XSUB
288 ) ? '__XSUB__' : Dumper( $weak_registry->{$addr}{weakref} )
289 0 ▶ ;
Branch: 1 branch
BranchTrueFalseTotal
ref $weak_registry->{$addr}{'weakref'} eq 'CODE' && B::svref_2object($weak_registry->{$addr}{'weakref'})->XSUB ? : 0 0 0
Condition0%0/3
ref $weak_registry->{$addr}{"weakref"} eq "CODE" and B::svref_2object($weak_registry->{$addr}{"weakref"})->XSUB
!ll&&!rl&&r
000
MC/DC0%0/2
ref $weak_registry->{$addr}{"weakref"} eq "CODE" and B::svref_2object($weak_registry->{$addr}{"weakref"})->XSUB
ref $weak_registry->{$addr}{"weakref"} eq "CODE" B::svref_2object($weak_registry->{$addr}{"weakref"})->XSUB
Truth table0%0/3
A and B
A= ref $weak_registry->{$addr}{"weakref"} eq "CODE"B= B::svref_2object($weak_registry->{$addr}{"weakref"})->XSUB
ABresult
0X0
100
111
290 };
291  
292 # FIXME - need to add a circular reference seeker based on the visitor
293 # (will need a bunch of modifications, punting with just a stub for now)
294  
295 $diag .= Devel::FindRef::track ($weak_registry->{$addr}{weakref}, 50) . "\n"
296 0 ▶ if ( $ENV{TEST_VERBOSE} && eval { require Devel::FindRef });
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"TEST_VERBOSE"} and eval { do { require Devel::FindRef } } 0 0 0
Condition0%0/3
$ENV{"TEST_VERBOSE"} and eval { do { require Devel::FindRef } }
!ll&&!rl&&r
000
MC/DC0%0/2
$ENV{"TEST_VERBOSE"} and eval { do { require Devel::FindRef } }
$ENV{"TEST_VERBOSE"} eval { do { require Devel::FindRef } }
Truth table0%0/3
A and B
A= $ENV{"TEST_VERBOSE"}B= eval { do { require Devel::FindRef } }
ABresult
0X0
100
111
297  
298 0 $diag =~ s/^/ /mg;
299  
300 0 ▶ if (my $stack = $weak_registry->{$addr}{stacktrace}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $stack = $weak_registry->{$addr}{"stacktrace"}) 0 0 0
301 0 $diag .= " Reference first seen$stack";
302 }
303  
304 0 $tb->diag($diag);
305  
306 # if ($leaks_found == 1) {
307 # # using the fh dumper due to intermittent buffering issues
308 # # in case we decide to exit soon after (possibly via _exit)
309 # require Devel::MAT::Dumper;
310 # local $Devel::MAT::Dumper::MAX_STRING = -1;
311 # open( my $fh, '>:raw', "leaked_${addr}_pid$$.pmat" ) or die $!;
312 # Devel::MAT::Dumper::dumpfh( $fh );
313 # close ($fh) or die $!;
314 #
315 # use POSIX;
316 # POSIX::_exit(1);
317 # }
318 }
319  
320 0 ▶ if (! $quiet and !$leaks_found and ! $tb->in_todo) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $quiet || $leaks_found || $tb->in_todo) 0 0 0
Condition0%0/6
$quiet || $leaks_found || $tb->in_todo
l!l&&r!l&&!r
000
$quiet or $leaks_found
l!l&&r!l&&!r
000
MC/DC0%0/3
$quiet || $leaks_found || $tb->in_todo
$quiet $leaks_found $tb->in_todo
Truth table0%0/4
A or B || C
A= $quietB= $leaks_foundC= $tb->in_todo
ABCresult
1XX1
01X1
0011
0000
321 0 $tb->ok(1, sprintf "No leaks found at %s line %d", (caller())[1,2] );
322 }
323 }
324  
325 2 ▶END {
Subroutine END: called CC=14 SCAR=36.5
326 2 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Test/Builder.pm"} and my $tb = do { local $@; my $t = eval { do { "Test::Builder"->new } } or warn "Test::Builder->new failed:\n$@\n"; $t }) 2 0 2
Condition33%1/3
$INC{"Test/Builder.pm"} and my $tb = do { local $@; my $t = eval { do { "Test::Builder"->new } } or warn "Test::Builder->new failed:\n$@\n"; $t }
!ll&&!rl&&r
002
MC/DC0%0/2
$INC{"Test/Builder.pm"} and my $tb = do { local $@; my $t = eval { do { "Test::Builder"->new } } or warn "Test::Builder->new failed:\n$@\n"; $t }
$INC{"Test/Builder.pm"} my $tb = do { local $@; my $t = eval { do { "Test::Builder"->new } } or warn "Test::Builder->new failed:\n$@\n"; $t }
Truth table33%1/3
A and B
A= $INC{"Test/Builder.pm"}B= my $tb = do { local $@; my $t = eval { do { "Test::Builder"->new } } or warn "Test::Builder->new failed:\n$@\n"; $t }
ABresult
0X0
100
111
327 $INC{'Test/Builder.pm'}
328 and
329 my $tb = do {
330 2 local $@;
331 2 ▶ my $t = eval { Test::Builder->new }
Branch: 1 branch
BranchTrueFalseTotal
my $t = eval { do { "Test::Builder"->new } } or warn "Test::Builder->new failed:\n$@\n" 2 0 2
332 or warn "Test::Builder->new failed:\n$@\n";
333 2 $t;
334 }
335 ) {
336 # we check for test passage - a leak may be a part of a TODO
337 2 ▶ if ($leaks_found and !$tb->is_passing) {
Branch: 1 branch
BranchTrueFalseTotal
if ($leaks_found and not $tb->is_passing) { } 0 2 2
Condition33%1/3
$leaks_found and not $tb->is_passing
!ll&&!rl&&r
200
MC/DC0%0/2
$leaks_found and not $tb->is_passing
$leaks_found not $tb->is_passing
Truth table33%1/3
A and not(B)
A= $leaks_foundB= not $tb->is_passing
ABresult
0X0
100
111
338  
339 $tb->diag(sprintf
340 "\n\n%s\n%s\n\nInstall Devel::FindRef and re-run the test with set "
341 . '$ENV{TEST_VERBOSE} (prove -v) to see a more detailed leak-report'
342 . "\n\n%s\n%s\n\n", ('#' x 16) x 4
343 0 ▶ ) if ( !$ENV{TEST_VERBOSE} or !$INC{'Devel/FindRef.pm'} );
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{"TEST_VERBOSE"} and $INC{"Devel/FindRef.pm"} 0 0 0
Condition0%0/3
$ENV{"TEST_VERBOSE"} and $INC{"Devel/FindRef.pm"}
!ll&&!rl&&r
000
MC/DC0%0/2
$ENV{"TEST_VERBOSE"} and $INC{"Devel/FindRef.pm"}
$ENV{"TEST_VERBOSE"} $INC{"Devel/FindRef.pm"}
Truth table0%0/3
A and B
A= $ENV{"TEST_VERBOSE"}B= $INC{"Devel/FindRef.pm"}
ABresult
0X0
100
111
344  
345 }
346 else {
347 2 $tb->note("Auto checked $refs_traced references for leaks - none detected");
348 }
349  
350 # also while we are here and not in plain runmode: make sure we never
351 # loaded any of the strictures XS bullshit (it's a leak in a sense)
352 2 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"MOO_FATAL_WARNINGS"} or $INC{"SQL/Translator.pm"} or not $ENV{"AUTOMATED_TESTING"} || $ENV{"RELEASE_TESTING"}) 2 0 2
Condition33%3/9
$ENV{"MOO_FATAL_WARNINGS"} or $INC{"SQL/Translator.pm"} or not $ENV{"AUTOMATED_TESTING"} || $ENV{"RELEASE_TESTING"}
l!l&&r!l&&!r
002
$ENV{"MOO_FATAL_WARNINGS"} or $INC{"SQL/Translator.pm"}
l!l&&r!l&&!r
002
$ENV{'AUTOMATED_TESTING'} || $ENV{'RELEASE_TESTING'}
l!l&&r!l&&!r
200
MC/DC0%0/4
$ENV{"MOO_FATAL_WARNINGS"} or $INC{"SQL/Translator.pm"} or not $ENV{"AUTOMATED_TESTING"} || $ENV{"RELEASE_TESTING"}
$ENV{"MOO_FATAL_WARNINGS"} $INC{"SQL/Translator.pm"} $ENV{'AUTOMATED_TESTING'} $ENV{'RELEASE_TESTING'}
Truth table20%1/5
A or B or not(C || D)
A= $ENV{"MOO_FATAL_WARNINGS"}B= $INC{"SQL/Translator.pm"}C= $ENV{'AUTOMATED_TESTING'}D= $ENV{'RELEASE_TESTING'}
ABCDresult
1XXX1
01XX1
00001
001X0
00010
353 $ENV{MOO_FATAL_WARNINGS}
354 or
355 # FIXME - SQLT loads strictures explicitly, /facedesk
356 # remove this INC check when 0fb58589 and 45287c815 are rectified
357 $INC{'SQL/Translator.pm'}
358 or
359 ( !$ENV{AUTOMATED_TESTING} && !$ENV{RELEASE_TESTING} )
360 ) {
361 2 for my $mod (qw(indirect multidimensional bareword::filehandles)) {
362 6 ( my $fn = "$mod.pm" ) =~ s|::|/|g;
363  
364 $tb->ok(0, "Load of '$mod' should not have been attempted!!!" )
365 6 ▶ if exists $INC{$fn};
Branch: 1 branch
BranchTrueFalseTotal
if exists $INC{$fn} 0 6 6
366 }
367 }
368 }
369 }
370  
371 2 1;
372  
373 __END__
« blib/lib/DBIO/ResultSource.pm ↑ Summary blib/lib/DBIO/Test/Schema.pm »