give the actual reason for this TODO
[gitmo/Moose.git] / t / bugs / memory_leaks.t
CommitLineData
98f27a2f 1use strict;
2use warnings;
3
4use Test::Requires {
8fada38c 5 'Test::LeakTrace' => '0.01',
6 'Test::Memory::Cycle' => '0',
98f27a2f 7};
8
9use Test::More;
10
1b0b5ee1 11use Moose ();
12use Moose::Util qw( apply_all_roles );
98f27a2f 13
14{
15 package MyRole;
16 use Moose::Role;
17 sub myname { "I'm a role" }
18}
983521d7 19
98f27a2f 20no_leaks_ok(
21 sub {
22 Moose::Meta::Class->create_anon_class->new_object;
23 },
24 'anonymous class with no roles is leak-free'
25);
26
27no_leaks_ok(
28 sub {
29 Moose::Meta::Role->initialize('MyRole2');
30 },
31 'Moose::Meta::Role->initialize is leak-free'
32);
33
34no_leaks_ok(
35 sub {
36 Moose::Meta::Class->create('MyClass2')->new_object;
37 },
38 'creating named class is leak-free'
39);
40
41no_leaks_ok(
42 sub {
dc77c65e 43 Moose::Meta::Class->create( 'MyClass', roles => ['MyRole'] );
98f27a2f 44 },
45 'named class with roles is leak-free'
46);
47
48no_leaks_ok(
49 sub {
1b0b5ee1 50 Moose::Meta::Role->create( 'MyRole2', roles => ['MyRole'] );
51 },
52 'named role with roles is leak-free'
53);
54
55no_leaks_ok(
56 sub {
57 my $object = Moose::Meta::Class->create('MyClass2')->new_object;
58 apply_all_roles( $object, 'MyRole' );
59 },
60 'applying role to an instance is leak-free'
61);
62
63no_leaks_ok(
64 sub {
98f27a2f 65 Moose::Meta::Role->create_anon_role;
66 },
67 'anonymous role is leak-free'
68);
69
1a58cce0 70{
74b9b2ff 71 # fixing this leak currently triggers a bug in Carp
72 # we can un-TODO once that fix goes in allowing the leak
73 # in Eval::Closure to be fixed
74 local $TODO = 'Eval::Closure leaks a bit at the moment';
1a58cce0 75 no_leaks_ok(
76 sub {
77 my $meta = Moose::Meta::Class->create_anon_class;
78 $meta->make_immutable;
79 },
80 'making an anon class immutable is leak-free'
81 );
82}
98f27a2f 83
8fada38c 84{
b360f8ae 85 my $meta3 = Moose::Meta::Class->create('MyClass3');
8fada38c 86 memory_cycle_ok( $meta3, 'named metaclass object is cycle-free' );
87 memory_cycle_ok( $meta3->new_object, 'MyClass3 object is cycle-free' );
88
b360f8ae 89 my $anon_class = Moose::Meta::Class->create_anon_class;
90 memory_cycle_ok($anon_class, 'anon metaclass object is cycle-free' );
91 memory_cycle_ok( $anon_class->new_object, 'object from anon metaclass is cycle-free' );
8fada38c 92
b360f8ae 93 $anon_class->make_immutable;
94 memory_cycle_ok($anon_class, 'immutable anon metaclass object is cycle-free' );
95 memory_cycle_ok( $anon_class->new_object, 'object from immutable anon metaclass is cycle-free' );
96
97 my $anon_role = Moose::Meta::Role->create_anon_role;
98 memory_cycle_ok($anon_role, 'anon role meta object is cycle-free' );
8fada38c 99}
100
98f27a2f 101done_testing;