Import Moose/t/100_bugs
[gitmo/Mouse.git] / t / 100_bugs / failing / 023_DEMOLISH_fails_without_metaclass.t
CommitLineData
4c98ebb0 1use strict;
2use warnings;
3
4use Test::More tests => 2;
5use Test::Exception;
6
7{
8 package MyClass;
9 use Mouse;
10
11 sub DEMOLISH { }
12}
13
14my $object = MyClass->new;
15
16# Removing the metaclass simulates the case where the metaclass object
17# goes out of scope _before_ the object itself, which under normal
18# circumstances only happens during global destruction.
19Class::MOP::remove_metaclass_by_name('MyClass');
20
21# The bug happened when DEMOLISHALL called
22# Class::MOP::class_of($object) and did not get a metaclass object
23# back.
24lives_ok { $object->DESTROY }
25'can call DESTROY on an object without a metaclass object in the CMOP cache';
26
27
28MyClass->meta->make_immutable;
29Class::MOP::remove_metaclass_by_name('MyClass');
30
31# The bug didn't manifest for immutable objects, but this test should
32# help us prevent it happening in the future.
33lives_ok { $object->DESTROY }
34'can call DESTROY on an object without a metaclass object in the CMOP cache (immutable version)';