Remove some debugging cruft
[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{
71 local $TODO
72 = 'Until we eliminate meta objects from being closed over by the immutabilized methods, this will leak';
73 no_leaks_ok(
74 sub {
75 my $meta = Moose::Meta::Class->create_anon_class;
76 $meta->make_immutable;
77 },
78 'making an anon class immutable is leak-free'
79 );
80}
98f27a2f 81
8fada38c 82{
b360f8ae 83 my $meta3 = Moose::Meta::Class->create('MyClass3');
8fada38c 84 memory_cycle_ok( $meta3, 'named metaclass object is cycle-free' );
85 memory_cycle_ok( $meta3->new_object, 'MyClass3 object is cycle-free' );
86
b360f8ae 87 my $anon_class = Moose::Meta::Class->create_anon_class;
88 memory_cycle_ok($anon_class, 'anon metaclass object is cycle-free' );
89 memory_cycle_ok( $anon_class->new_object, 'object from anon metaclass is cycle-free' );
8fada38c 90
b360f8ae 91 $anon_class->make_immutable;
92 memory_cycle_ok($anon_class, 'immutable anon metaclass object is cycle-free' );
93 memory_cycle_ok( $anon_class->new_object, 'object from immutable anon metaclass is cycle-free' );
94
95 my $anon_role = Moose::Meta::Role->create_anon_role;
96 memory_cycle_ok($anon_role, 'anon role meta object is cycle-free' );
8fada38c 97}
98
98f27a2f 99done_testing;