From: gfx Date: Fri, 21 Aug 2009 08:41:03 +0000 (+0900) Subject: Add t/314_method_leak.t for memory leak testing X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=575a3c54dc1ae8554c98b377b65b13e0e4bcce3b;p=gitmo%2FClass-MOP.git Add t/314_method_leak.t for memory leak testing --- diff --git a/t/314_method_leak.t b/t/314_method_leak.t new file mode 100755 index 0000000..6e97451 --- /dev/null +++ b/t/314_method_leak.t @@ -0,0 +1,59 @@ +use strict; +use warnings; + +use Test::More; +use Devel::Peek; + +BEGIN { + eval "use Test::LeakTrace;"; + plan skip_all => "Test::LeakTrace is required for this test" if $@; +} + +use Test::More tests => 6; +use Class::MOP; + +{ + package Foo; + use metaclass; +} + +leaks_cmp_ok { + my $meta = Foo->meta; + $meta->add_method(foo => sub{ 42 }); + $meta->remove_method('foo'); +} '<=', 0, 'add_method and remove_method'; + + +my $expected = ($] == 5.010_000) ? 1 : 0; # for a bug on 5.10.0 + +leaks_cmp_ok { + my $meta = Foo->meta; + $meta->add_attribute(foo => (reader => 'foo')); + $meta->remove_attribute('foo'); +} '<=', $expected, 'add_attribute with reader and remove_attribute'; + +leaks_cmp_ok { + my $meta = Foo->meta; + $meta->add_attribute(foo => (writer => 'foo')); + $meta->remove_attribute('foo'); +} '<=', $expected, 'add_attribute with writer and remove_attribute'; + + +leaks_cmp_ok { + my $meta = Foo->meta; + $meta->add_attribute(foo => (accessor => 'foo')); + $meta->remove_attribute('foo'); +} '<=', $expected, 'add_attribute with accessor and remove_attribute'; + +leaks_cmp_ok { + my $meta = Foo->meta; + $meta->add_attribute(foo => (predicate => 'foo')); + $meta->remove_attribute('foo'); +} '<=', $expected, 'add_attribute with predicate and remove_attribute'; + +leaks_cmp_ok { + my $meta = Foo->meta; + $meta->add_attribute(foo => (clearer => 'foo')); + $meta->remove_attribute('foo'); +} '<=', $expected, 'add_attribute with clearer and remove_attribute'; +