Clean up this test (tidy, improve test descriptions)
[gitmo/Class-MOP.git] / t / 500_deprecated.t
1 use strict;
2 use warnings;
3
4 use Test::More tests => 6;
5 use Test::Exception;
6
7 use Carp;
8
9 $SIG{__WARN__} = \&croak;
10
11 {
12     package Foo;
13
14     ::throws_ok{
15         Class::MOP::in_global_destruction();
16         } qr/\b deprecated \b/xmsi,
17         'Class::MOP::in_global_destruction is deprecated';
18 }
19
20 {
21     package Bar;
22
23     use Class::MOP::Deprecated -compatible => 0.93;
24
25     ::throws_ok{
26         Class::MOP::in_global_destruction();
27         } qr/\b deprecated \b/xmsi,
28         'Class::MOP::in_global_destruction is deprecated with 0.93 compatibility';
29 }
30
31 {
32     package Baz;
33
34     use Class::MOP::Deprecated -compatible => 0.92;
35
36     ::lives_ok{
37         Class::MOP::in_global_destruction();
38         }
39         'Class::MOP::in_global_destruction is not deprecated with 0.92 compatibility';
40 }
41
42 {
43     package Baz::Inner;
44
45     ::lives_ok{
46         Class::MOP::in_global_destruction();
47         } 'safe in an inner class';
48 }
49
50 {
51     package Quux;
52
53     use Class::MOP::Deprecated -compatible => 0.92;
54     use Scalar::Util qw( blessed );
55
56     use metaclass;
57
58     sub foo {42}
59
60     Quux->meta->add_method( bar => sub {84} );
61
62     my $map = Quux->meta->get_method_map;
63     my @method_objects = grep { blessed($_) } values %{$map};
64
65     ::is(
66         scalar @method_objects, 3,
67         'get_method_map still returns all values as method object'
68     );
69     ::is_deeply(
70         [ sort keys %{$map} ],
71         [qw( bar foo meta )],
72         'get_method_map returns expected methods'
73     );
74 }