Skip to content

Commit

Permalink
Item13897: Additional support for Unit::Leak::Object.
Browse files Browse the repository at this point in the history
  • Loading branch information
vrurg committed May 18, 2017
1 parent 0dcf5d6 commit 7f153ad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
13 changes: 2 additions & 11 deletions UnitTestContrib/lib/Unit/FoswikiTestRole.pm
Expand Up @@ -17,15 +17,6 @@ use File::Spec;
use Scalar::Util qw(blessed);
use Foswiki::Exception;

BEGIN {
if (Unit::TestRunner::CHECKLEAK) {
eval "use Devel::Leak::Object qw{ GLOBAL_bless };";
die $@ if $@;
$Devel::Leak::Object::TRACKSOURCELINES = 1;
$Devel::Leak::Object::TRACKSTACK = 1;
}
}

# Use variable to let it be easily incorporated into a regex.
our $TEST_WEB_PREFIX = 'Temporary';

Expand Down Expand Up @@ -778,7 +769,7 @@ sub leakDetectCheckpoint {

say STDERR "<<< LEAK CHECKPOINT FOR TEST ", $dumpName;

return Devel::Leak::Object::checkpoint();
return $Unit::TestRunner::checkpointSub->();
}

=begin TML
Expand Down Expand Up @@ -808,7 +799,7 @@ sub leakDetectDump {

$dumpName =~ tr/:/_/;
say STDERR ">>> LEAK DUMP FOR TEST ", $dumpName;
Devel::Leak::Object::status();
$Unit::TestRunner::statusSub->();
eval {
require Devel::MAT::Dumper;
my $pmatFile = File::Spec->catfile( $this->app->cfg->data->{Log}{Dir},
Expand Down
25 changes: 20 additions & 5 deletions UnitTestContrib/lib/Unit/TestRunner.pm
Expand Up @@ -25,12 +25,27 @@ extends qw(Foswiki::Object);

sub CHECKLEAK { 0 || $ENV{FOSWIKI_CHECKLEAK} }

our ( $leakClass, $checkpointSub, $statusSub );

BEGIN {
if (CHECKLEAK) {
eval "use Devel::Leak::Object qw{ GLOBAL_bless };";
die $@ if $@;
$Devel::Leak::Object::TRACKSOURCELINES = 1;
$Devel::Leak::Object::TRACKSTACK = 1;
my $succeed = 0;
foreach $leakClass (qw(Unit::Leak::Object Devel::Leak::Object)) {
eval "use $leakClass qw{ GLOBAL_bless };";
if ($@) {
say STDERR "!!! Failed to load $leakClass\n", $@;
}
else {
eval "
\$${leakClass}::TRACKSOURCELINES = 1;
\$${leakClass}::TRACKSTACK = 1;";
$checkpointSub = $leakClass->can('checkpoint');
$statusSub = $leakClass->can('status');
$succeed = 1;
last;
}
}
die "Cannot load a leak-check module" unless $succeed;
}
}

Expand Down Expand Up @@ -608,7 +623,7 @@ sub runOne {
print "SKIP\t$test - $skip\n";
}
else {
Devel::Leak::Object::checkpoint() if CHECKLEAK;
$checkpointSub->() if CHECKLEAK;
print "\t$test\n";
$action .= "\n# $test\n ";

Expand Down
4 changes: 2 additions & 2 deletions core/bin/foswiki_debug.psgi
Expand Up @@ -35,8 +35,8 @@ BEGIN {
}
use Plack::Builder;
use Foswiki::App;
use Devel::Leak;
use Devel::Leak::Object;
#use Devel::Leak;
#use Devel::Leak::Object;

use constant CHECKLEAK => $ENV{FOSWIKI_CHECKLEAK} // 0;

Expand Down

0 comments on commit 7f153ad

Please sign in to comment.