make check_metaclass_compatibility private
[gitmo/Class-MOP.git] / t / 071_immutable_w_custom_metaclass.t
CommitLineData
373a16ae 1use strict;
2use warnings;
3
04dd7510 4use FindBin;
5use File::Spec::Functions;
6
efd3d14c 7use Test::More tests => 14;
373a16ae 8use Test::Exception;
04dd7510 9use Scalar::Util;
373a16ae 10
efd3d14c 11use Class::MOP;
373a16ae 12
04dd7510 13use lib catdir($FindBin::Bin, 'lib');
14
373a16ae 15{
04dd7510 16 package Foo;
17
373a16ae 18 use strict;
19 use warnings;
04dd7510 20 use metaclass;
21
22 __PACKAGE__->meta->make_immutable;
373a16ae 23
373a16ae 24 package Bar;
04dd7510 25
373a16ae 26 use strict;
27 use warnings;
04dd7510 28 use metaclass;
29
373a16ae 30 __PACKAGE__->meta->make_immutable;
04dd7510 31
373a16ae 32 package Baz;
04dd7510 33
373a16ae 34 use strict;
35 use warnings;
04dd7510 36 use metaclass 'MyMetaClass';
37
38 sub mymetaclass_attributes{
39 shift->meta->mymetaclass_attributes;
40 }
373a16ae 41
42 ::lives_ok {
04dd7510 43 Baz->meta->superclasses('Bar');
abfebb52 44 } '... we survive the metaclass incompatibility test';
373a16ae 45}
46
04dd7510 47{
48 my $meta = Baz->meta;
d9586da2 49 ok($meta->is_mutable, '... Baz is mutable');
b5ade142 50 isnt(Scalar::Util::blessed(Foo->meta), Scalar::Util::blessed(Bar->meta),
51 'Foo and Bar immutable metaclasses do not match');
11b56828 52 is(Scalar::Util::blessed($meta), 'MyMetaClass', 'Baz->meta blessed as MyMetaClass');
04dd7510 53 ok(Baz->can('mymetaclass_attributes'), '... Baz can do method before immutable');
54 ok($meta->can('mymetaclass_attributes'), '... meta can do method before immutable');
d9586da2 55 lives_ok { $meta->make_immutable } "Baz is now immutable";
56 ok($meta->is_immutable, '... Baz is immutable');
04dd7510 57 isa_ok($meta, 'MyMetaClass', 'Baz->meta');
58 ok(Baz->can('mymetaclass_attributes'), '... Baz can do method after imutable');
59 ok($meta->can('mymetaclass_attributes'), '... meta can do method after immutable');
11b56828 60 isnt(Scalar::Util::blessed(Baz->meta), Scalar::Util::blessed(Bar->meta), 'Baz and Bar immutable metaclasses are different');
d9586da2 61 lives_ok { $meta->make_mutable } "Baz is now mutable";
62 ok($meta->is_mutable, '... Baz is mutable again');
04dd7510 63}