Revert "convert all uses of Test::Exception to Test::Fatal."
[gitmo/Class-MOP.git] / t / 074_immutable_custom_trait.t
CommitLineData
73d6ccc2 1use strict;
2use warnings;
3
86a4d873 4use Test::More;
8371f3de 5use Test::Exception;
73d6ccc2 6
7use Class::MOP;
8
9{
10
11 package My::Meta;
12
13 use strict;
14 use warnings;
73d6ccc2 15
16 use base 'Class::MOP::Class';
17
18 sub initialize {
19 shift->SUPER::initialize(
20 @_,
21 immutable_trait => 'My::Meta::Class::Immutable::Trait',
22 );
23 }
24}
25
26{
27 package My::Meta::Class::Immutable::Trait;
28
29 use MRO::Compat;
30 use base 'Class::MOP::Class::Immutable::Trait';
31
32 sub another_method { 42 }
33
34 sub superclasses {
35 my $orig = shift;
36 my $self = shift;
37 $self->$orig(@_);
38 }
39}
40
41{
42 package Foo;
43
44 use strict;
45 use warnings;
46 use metaclass;
47
48 __PACKAGE__->meta->add_attribute('foo');
49
50 __PACKAGE__->meta->make_immutable;
51}
52
53{
54 package Bar;
55
56 use strict;
57 use warnings;
58 use metaclass 'My::Meta';
59
60 use base 'Foo';
61
62 __PACKAGE__->meta->add_attribute('bar');
63
8371f3de 64 ::lives_ok { __PACKAGE__->meta->make_immutable }
73d6ccc2 65 'can safely make a class immutable when it has a custom metaclass and immutable trait';
66}
67
68{
69 can_ok( Bar->meta, 'another_method' );
70 is( Bar->meta->another_method, 42, 'another_method returns expected value' );
71 is_deeply(
72 [ Bar->meta->superclasses ], ['Foo'],
73 'Bar->meta->superclasses returns expected value after immutabilization'
74 );
75}
86a4d873 76
77done_testing;