Commit | Line | Data |
dc4fc8c7 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::Exception; |
5 | use Test::More; |
6 | use Test::Warn; |
7 | |
8 | { |
9 | throws_ok { |
10 | eval 'package Foo; use Package::DeprecationManager;'; |
11 | die $@ if $@; |
12 | } |
13 | qr/^\QYou must provide a hash reference -deprecations parameter when importing Package::DeprecationManager/, |
14 | 'must provide a set of deprecations when using Package::DeprecationManager'; |
15 | } |
16 | |
17 | { |
18 | package Foo; |
19 | |
20 | use Package::DeprecationManager -deprecations => { |
21 | 'Foo::foo' => '0.02', |
22 | 'Foo::bar' => '0.03', |
23 | 'Foo::baz' => '1.21', |
24 | }; |
25 | |
26 | sub foo { |
27 | deprecated('foo is deprecated'); |
28 | } |
29 | |
30 | sub bar { |
31 | deprecated('bar is deprecated'); |
32 | } |
33 | |
34 | sub baz { |
35 | deprecated(); |
36 | } |
37 | } |
38 | |
39 | { |
40 | package Bar; |
41 | |
42 | Foo->import(); |
43 | |
44 | ::warning_is{ Foo::foo() } |
45 | { carped => 'foo is deprecated' }, |
46 | 'deprecation warning for foo'; |
47 | |
48 | ::warning_is{ Foo::bar() } |
49 | { carped => 'bar is deprecated' }, |
50 | 'deprecation warning for bar'; |
51 | |
52 | ::warning_is{ Foo::baz() } |
53 | { carped => 'Foo::baz has been deprecated since version 1.21' }, |
54 | 'deprecation warning for baz, and message is generated by Package::DeprecationManager'; |
55 | |
56 | ::warning_is{ Foo::foo() } q{}, 'no warning on second call to foo'; |
57 | |
58 | ::warning_is{ Foo::bar() } q{}, 'no warning on second call to bar'; |
59 | |
60 | ::warning_is{ Foo::baz() } q{}, 'no warning on second call to baz'; |
61 | } |
62 | |
63 | { |
64 | package Baz; |
65 | |
66 | Foo->import( -api_version => '0.01' ); |
67 | |
68 | ::warning_is{ Foo::foo() } |
69 | q{}, |
70 | 'no warning for foo with api_version = 0.01'; |
71 | |
72 | ::warning_is{ Foo::bar() } |
73 | q{}, |
74 | 'no warning for bar with api_version = 0.01'; |
75 | |
76 | ::warning_is{ Foo::baz() } |
77 | q{}, |
78 | 'no warning for baz with api_version = 0.01'; |
79 | } |
80 | |
81 | |
82 | { |
83 | package Quux; |
84 | |
85 | Foo->import( -api_version => '1.17' ); |
86 | |
87 | ::warning_is{ Foo::foo() } |
88 | { carped => 'foo is deprecated' }, |
89 | 'deprecation warning for foo with api_version = 1.17'; |
90 | |
91 | ::warning_is{ Foo::bar() } |
92 | { carped => 'bar is deprecated' }, |
93 | 'deprecation warning for bar with api_version = 1.17'; |
94 | |
95 | ::warning_is{ Foo::baz() } |
96 | q{}, |
97 | 'no warning for baz with api_version = 1.17'; |
98 | } |
99 | |
100 | done_testing(); |