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