Add tests for memory leaks
Dave Rolsky [Sun, 19 Feb 2012 18:10:19 +0000 (12:10 -0600)]
Some of these tests are failing right now.

t/bugs/memory_leaks.t [new file with mode: 0644]

diff --git a/t/bugs/memory_leaks.t b/t/bugs/memory_leaks.t
new file mode 100644 (file)
index 0000000..ed3334a
--- /dev/null
@@ -0,0 +1,63 @@
+use strict;
+use warnings;
+
+use Test::Requires {
+    'Test::LeakTrace' => '0.01',
+};
+
+use Test::More;
+
+use Moose;
+
+{
+    package MyRole;
+    use Moose::Role;
+    sub myname { "I'm a role" }
+}
+
+no_leaks_ok(
+    sub {
+        Moose::Meta::Class->create_anon_class->new_object;
+    },
+    'anonymous class with no roles is leak-free'
+);
+
+no_leaks_ok(
+    sub {
+        Moose::Meta::Role->initialize('MyRole2');
+    },
+    'Moose::Meta::Role->initialize is leak-free'
+);
+
+no_leaks_ok(
+    sub {
+        Moose::Meta::Class->create('MyClass2')->new_object;
+    },
+    'creating named class is leak-free'
+);
+
+no_leaks_ok(
+    sub {
+        Moose::Meta::Class->create( 'MyClass', roles => ['MyRole'] )
+            ->new_object;
+    },
+    'named class with roles is leak-free'
+);
+
+no_leaks_ok(
+    sub {
+        Moose::Meta::Role->create_anon_role;
+    },
+    'anonymous role is leak-free'
+);
+
+no_leaks_ok(
+    sub {
+        my $meta = Moose::Meta::Class->create_anon_class;
+        $meta->make_immutable;
+        $meta->new_object;
+    },
+    'making an anon class immutable is leak-free'
+);
+
+done_testing;