From: gfx Date: Sun, 1 Nov 2009 04:09:24 +0000 (+0900) Subject: Add memory leak tests for type constraints and accessors X-Git-Tag: 0.40_05~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=460eb22dd849bdfdd8dd73c22799ca37bfbf2ec8;p=gitmo%2FMouse.git Add memory leak tests for type constraints and accessors --- diff --git a/t/001_mouse/058-accessor-leaks.t b/t/001_mouse/058-accessor-leaks.t new file mode 100644 index 0000000..f026c08 --- /dev/null +++ b/t/001_mouse/058-accessor-leaks.t @@ -0,0 +1,70 @@ +#!perl +# This is based on Class-MOP/t/312_anon_class_leak.t +use strict; +use warnings; +use Test::More; + +BEGIN { + eval "use Test::LeakTrace 0.10;"; + plan skip_all => "Test::LeakTrace 0.10 is required for this test" if $@; +} + +plan tests => 11; + +{ + package MyClass; + use Mouse; + + has simple => (is => 'rw'); + + has w_int => (is => 'rw', isa => 'Int'); + has w_int_or_undef + => (is => 'rw', isa => 'Int | Undef'); + has w_foo => (is => 'rw', isa => 'Foo'); + has w_aint=> (is => 'rw', isa => 'ArrayRef[Int]'); +} + +no_leaks_ok{ + MyClass->new(); +}; + +my $o = MyClass->new; +no_leaks_ok { + $o->simple(10); +}; +no_leaks_ok { + $o->simple(); +}; + +no_leaks_ok { + $o->w_int(10); +}; +no_leaks_ok { + $o->w_int(); +}; + +no_leaks_ok { + $o->w_int_or_undef(10); +}; +no_leaks_ok { + $o->w_int_or_undef(); +}; + +my $foo = bless {}, 'Foo'; +no_leaks_ok { + $o->w_foo($foo); +}; +no_leaks_ok { + $o->w_int(); +}; + +my $aref = [10]; +no_leaks_ok { + $o->w_aint($aref); +}; +no_leaks_ok { + $o->w_aint(); +}; + + +