Merge branch 'stable'
[gitmo/Class-MOP.git] / t / 500_deprecated.t
CommitLineData
30229767 1use strict;
2use warnings;
3
86a4d873 4use Test::More;
871e9eb5 5use Test::Fatal;
30229767 6
7use Carp;
8
9$SIG{__WARN__} = \&croak;
10
11{
12 package Foo;
30229767 13
871e9eb5 14 ::like( ::exception {
30229767 15 Class::MOP::in_global_destruction();
871e9eb5 16 }, qr/\b deprecated \b/xmsi, 'Class::MOP::in_global_destruction is deprecated' );
30229767 17}
18
19{
20 package Bar;
30229767 21
1b948345 22 use Class::MOP::Deprecated -api_version => 0.93;
30229767 23
871e9eb5 24 ::like( ::exception {
30229767 25 Class::MOP::in_global_destruction();
871e9eb5 26 }, qr/\b deprecated \b/xmsi, 'Class::MOP::in_global_destruction is deprecated with 0.93 compatibility' );
30229767 27}
28
29{
30 package Baz;
30229767 31
1b948345 32 use Class::MOP::Deprecated -api_version => 0.92;
30229767 33
871e9eb5 34 ::is( ::exception {
30229767 35 Class::MOP::in_global_destruction();
871e9eb5 36 }, undef, 'Class::MOP::in_global_destruction is not deprecated with 0.92 compatibility' );
30229767 37}
38
30229767 39{
b1aaf0dc 40 package Foo2;
41
42 use metaclass;
43
871e9eb5 44 ::like( ::exception { Foo2->meta->get_attribute_map }, qr/\Qget_attribute_map method has been deprecated/, 'get_attribute_map is deprecated' );
b1aaf0dc 45}
46
47{
b409c969 48 package Quux;
49
1b948345 50 use Class::MOP::Deprecated -api_version => 0.92;
b409c969 51 use Scalar::Util qw( blessed );
52
53 use metaclass;
54
55 sub foo {42}
56
57 Quux->meta->add_method( bar => sub {84} );
58
59 my $map = Quux->meta->get_method_map;
60 my @method_objects = grep { blessed($_) } values %{$map};
61
e8f79d90 62 ::is(
63 scalar @method_objects, 3,
64 'get_method_map still returns all values as method object'
65 );
66 ::is_deeply(
67 [ sort keys %{$map} ],
68 [qw( bar foo meta )],
69 'get_method_map returns expected methods'
70 );
b409c969 71}
86a4d873 72
73done_testing;