Skip Menu |

This queue is for tickets about the Test-LeakTrace CPAN distribution.

Report information
The Basics
Id: 48326
Status: resolved
Priority: 0/
Queue: Test-LeakTrace

People
Owner: Nobody in particular
Requestors: PUBNOOP [...] cpan.org
Cc: module-build [...] perl.org
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



CC: module-build [...] perl.org
Subject: patch to allow embedded ok() calls in block in no_leaks_ok
I have a test script like: use Test::More; ... my $thing = ... do_stuff_to($thing); is( get_stuff_from($thing), ... ); ok( $thing->do_otherstuff, ... ); ... I would like to adapt this test to check for memory leaks at the same time, with something like: use Test::More; use Test::LeakTrace; ... no_leaks_ok { my $thing = ... do_stuff_to($thing); is( get_stuff_from($thing), ... ); ok( $thing->do_otherstuff, ... ); ... }; ... but that won't currently work because the ok() call creates scalars that survive the block (causing false positive leak alerts) and no_leaks_ok runs the block more than once, messing up the test counts. The attached patch is the Test::LeakTrace side of a fix for this. It also requires a change to Module::Build to add a disable() method to temporarily make ok() and friends into no-ops. Module::Build maintainers cc-ed.
Subject: patch.txt
--- /usr/local/lib/perl/5.10.0/Test/LeakTrace.pm 2009-07-01 08:30:26.000000000 +0200 +++ /tmp/LeakTrace.pm 2009-07-30 17:10:01.000000000 +0200 @@ -73,15 +73,19 @@ my $Test = __PACKAGE__->builder; + # call to prepare cache in $block, and to run the tests if block includes + # calls to ok(), is(), fail(), etc. + $block->(); + if(!_runops_installed()){ my $mod = exists $INC{'Devel/Cover.pm'} ? 'Devel::Cover' : 'strange runops routines'; return $Test->ok(1, "skipped (under $mod)"); } - # calls to prepare cache in $block - $block->(); - + # suppress the side effects of ok() etc calls within the block. + $Test->disable(1); my $got = _do_leaktrace($block, 'leaked_count', 0); + $Test->disable(0); my $desc = sprintf 'leaks %s %-2s %s', $got, $cmp_op, $expected; if(defined $description){
RT-Send-CC: schwern [...] pobox.com, module-build [...] perl.org
On Thu Jul 30 11:14:09 2009, PUBNOOP wrote: Show quoted text
> I have a test script like: > > > use Test::More; > > ... > > my $thing = ... > do_stuff_to($thing); > > is( get_stuff_from($thing), ... ); > ok( $thing->do_otherstuff, ... ); > ... > > > I would like to adapt this test to check for memory leaks at the same > time, with something like: > > > use Test::More; > use Test::LeakTrace; > > ... > > no_leaks_ok { > my $thing = ... > do_stuff_to($thing); > > is( get_stuff_from($thing), ... ); > ok( $thing->do_otherstuff, ... ); > ... > }; > > > ... but that won't currently work because the ok() call creates scalars > that survive the block (causing false positive leak alerts) and > no_leaks_ok runs the block more than once, messing up the test counts. > > The attached patch is the Test::LeakTrace side of a fix for this. It > also requires a change to Module::Build to add a disable() method to > temporarily make ok() and friends into no-ops. Module::Build > maintainers cc-ed.
Sorry, brain fart, I meant Test::Builder not Module::Build.
As per https://github.com/Test-More/test-more/issues/547 - This currently can't be fixed. Closing.