add another author dep
[gitmo/Moose.git] / t / bugs / memory_leaks.t
CommitLineData
634a98c9 1use strict;
2use warnings;
3
4use Test::Requires {
5 'Test::LeakTrace' => '0.01',
6 'Test::Memory::Cycle' => '0',
7};
8
9use Test::More;
10
11use Moose ();
12use Moose::Util qw( apply_all_roles );
13
14{
15 package MyRole;
16 use Moose::Role;
17 sub myname { "I'm a role" }
18}
19
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
41{
42 local $TODO
43 = 'role application leaks because we end up applying the role more than once to the meta object';
44 no_leaks_ok(
45 sub {
46 Moose::Meta::Class->create( 'MyClass', roles => ['MyRole'] );
47 },
48 'named class with roles is leak-free'
49 );
50
51 no_leaks_ok(
52 sub {
53 Moose::Meta::Role->create( 'MyRole2', roles => ['MyRole'] );
54 },
55 'named role with roles is leak-free'
56 );
57}
58
59no_leaks_ok(
60 sub {
61 my $object = Moose::Meta::Class->create('MyClass2')->new_object;
62 apply_all_roles( $object, 'MyRole' );
63 },
64 'applying role to an instance is leak-free'
65);
66
67no_leaks_ok(
68 sub {
69 Moose::Meta::Role->create_anon_role;
70 },
71 'anonymous role is leak-free'
72);
73
74{
75 local $TODO
76 = 'Until we eliminate meta objects from being closed over by the immutabilized methods, this will leak';
77 no_leaks_ok(
78 sub {
79 my $meta = Moose::Meta::Class->create_anon_class;
80 $meta->make_immutable;
81 },
82 'making an anon class immutable is leak-free'
83 );
84}
85
86{
87 my $meta3 = Moose::Meta::Class->create('MyClass3');
88 memory_cycle_ok( $meta3, 'named metaclass object is cycle-free' );
89 memory_cycle_ok( $meta3->new_object, 'MyClass3 object is cycle-free' );
90
91 my $anon_class = Moose::Meta::Class->create_anon_class;
92 memory_cycle_ok($anon_class, 'anon metaclass object is cycle-free' );
93 memory_cycle_ok( $anon_class->new_object, 'object from anon metaclass is cycle-free' );
94
95 $anon_class->make_immutable;
96 memory_cycle_ok($anon_class, 'immutable anon metaclass object is cycle-free' );
97 memory_cycle_ok( $anon_class->new_object, 'object from immutable anon metaclass is cycle-free' );
98
99 my $anon_role = Moose::Meta::Role->create_anon_role;
100 memory_cycle_ok($anon_role, 'anon role meta object is cycle-free' );
101}
102
103done_testing;