This test does pass (but we'll keep it since apparently it was broken
[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
da763536 13use lib catdir( $FindBin::Bin, 'lib' );
04dd7510 14
373a16ae 15{
da763536 16
04dd7510 17 package Foo;
18
373a16ae 19 use strict;
20 use warnings;
04dd7510 21 use metaclass;
22
23 __PACKAGE__->meta->make_immutable;
373a16ae 24
373a16ae 25 package Bar;
04dd7510 26
373a16ae 27 use strict;
28 use warnings;
04dd7510 29 use metaclass;
30
373a16ae 31 __PACKAGE__->meta->make_immutable;
04dd7510 32
373a16ae 33 package Baz;
04dd7510 34
373a16ae 35 use strict;
36 use warnings;
04dd7510 37 use metaclass 'MyMetaClass';
38
da763536 39 sub mymetaclass_attributes {
40 shift->meta->mymetaclass_attributes;
04dd7510 41 }
373a16ae 42
467e2a81 43 ::lives_ok{ Baz->meta->superclasses('Bar') }
44 '... we survive the metaclass incompatibility test';
373a16ae 45}
46
04dd7510 47{
48 my $meta = Baz->meta;
da763536 49 ok( $meta->is_mutable, '... Baz is mutable' );
f5d08022 50 is(
da763536 51 Scalar::Util::blessed( Foo->meta ),
52 Scalar::Util::blessed( Bar->meta ),
f5d08022 53 'Foo and Bar immutable metaclasses match'
da763536 54 );
55 is( Scalar::Util::blessed($meta), 'MyMetaClass',
56 'Baz->meta blessed as MyMetaClass' );
57 ok( Baz->can('mymetaclass_attributes'),
58 '... Baz can do method before immutable' );
59 ok( $meta->can('mymetaclass_attributes'),
60 '... meta can do method before immutable' );
d9586da2 61 lives_ok { $meta->make_immutable } "Baz is now immutable";
da763536 62 ok( $meta->is_immutable, '... Baz is immutable' );
63 isa_ok( $meta, 'MyMetaClass', 'Baz->meta' );
64 ok( Baz->can('mymetaclass_attributes'),
65 '... Baz can do method after imutable' );
66 ok( $meta->can('mymetaclass_attributes'),
67 '... meta can do method after immutable' );
68 isnt( Scalar::Util::blessed( Baz->meta ),
69 Scalar::Util::blessed( Bar->meta ),
70 'Baz and Bar immutable metaclasses are different' );
d9586da2 71 lives_ok { $meta->make_mutable } "Baz is now mutable";
da763536 72 ok( $meta->is_mutable, '... Baz is mutable again' );
04dd7510 73}