From: Graham Knop Date: Fri, 19 Jun 2020 21:33:19 +0000 (+0200) Subject: include our own leak checking code rather than using CatalystX::LeakCheck X-Git-Tag: v5.90_127~10^2~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=fa2d8e3857cd3960f868d393e913377bd13f57a2 include our own leak checking code rather than using CatalystX::LeakCheck Most of CatalystX::LeakCheck is related to formatting output. We can inline the bit we need for the tests, which eliminates a circular dependency for developers. --- diff --git a/Makefile.PL b/Makefile.PL index c0ef18f..cfe61ef 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -84,7 +84,6 @@ my %META = ( }, develop => { requires => { - 'CatalystX::LeakChecker' => '0.05', 'Test::TCP' => '2.00', 'File::Copy::Recursive' => '0.40', 'Starman' => 0, diff --git a/t/lib/TestApp.pm b/t/lib/TestApp.pm index 3d50a73..20d12f7 100644 --- a/t/lib/TestApp.pm +++ b/t/lib/TestApp.pm @@ -60,23 +60,35 @@ TestApp->config( # above ->setup so we have some generated methods to be double sure. has an_attribute_before_we_change_base_classes => ( is => 'ro'); -if ($::setup_leakchecker && try_load_class('CatalystX::LeakChecker')) { - with 'CatalystX::LeakChecker'; +if ($::setup_leakchecker) { + require Scalar::Util; + require Devel::Cycle; has leaks => ( is => 'ro', default => sub { [] }, ); -} -sub found_leaks { - my ($ctx, @leaks) = @_; - push @{ $ctx->leaks }, @leaks; -} + sub count_leaks { + my ($ctx) = @_; + return scalar @{ $ctx->leaks }; + } + + after finalize => sub { + my ($ctx) = @_; + my @leaks; + + my $weak_ctx = $ctx; + Scalar::Util::weaken $weak_ctx; + + Devel::Cycle::find_cycle($ctx, sub { + my ($path) = @_; + push @leaks, $path + if $path->[0]->[2] == $weak_ctx; + }); -sub count_leaks { - my ($ctx) = @_; - return scalar @{ $ctx->leaks }; + push @{ $ctx->leaks }, @leaks; + }; } TestApp->setup; diff --git a/t/live_component_controller_context_closure.t b/t/live_component_controller_context_closure.t index 69fa504..ff0bbe9 100644 --- a/t/live_component_controller_context_closure.t +++ b/t/live_component_controller_context_closure.t @@ -3,8 +3,8 @@ use warnings; use Test::More; BEGIN { - unless (eval 'use CatalystX::LeakChecker 0.05; 1') { - plan skip_all => 'CatalystX::LeakChecker 0.05 required for this test'; + unless (eval 'use Devel::Cycle 1.11; 1') { + plan skip_all => 'Devel::Cycle 1.11 required for this test'; } plan tests => 6;