Commit | Line | Data |
dc4fc8c7 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::Exception; |
5 | use Test::More; |
2542cb3d |
6 | |
7 | use Test::Requires { |
748d15e6 |
8 | 'Test::Output' => '0.16', |
2542cb3d |
9 | }; |
dc4fc8c7 |
10 | |
11 | { |
12 | throws_ok { |
13 | eval 'package Foo; use Package::DeprecationManager;'; |
14 | die $@ if $@; |
15 | } |
16 | qr/^\QYou must provide a hash reference -deprecations parameter when importing Package::DeprecationManager/, |
17 | 'must provide a set of deprecations when using Package::DeprecationManager'; |
18 | } |
19 | |
20 | { |
21 | package Foo; |
22 | |
23 | use Package::DeprecationManager -deprecations => { |
bce3492c |
24 | 'Foo::foo' => '0.02', |
25 | 'Foo::bar' => '0.03', |
26 | 'Foo::baz' => '1.21', |
27 | 'not a sub' => '1.23', |
dc4fc8c7 |
28 | }; |
29 | |
30 | sub foo { |
31 | deprecated('foo is deprecated'); |
32 | } |
33 | |
34 | sub bar { |
35 | deprecated('bar is deprecated'); |
36 | } |
37 | |
38 | sub baz { |
39 | deprecated(); |
40 | } |
bce3492c |
41 | |
42 | sub quux { |
43 | if ( $_[0] > 5 ) { |
44 | deprecated( |
45 | message => 'quux > 5 has been deprecated', |
46 | feature => 'not a sub', |
47 | ); |
48 | } |
49 | } |
c9ed2327 |
50 | |
51 | sub varies { |
52 | deprecated("The varies sub varies: $_[0]"); |
53 | } |
54 | |
dc4fc8c7 |
55 | } |
56 | |
57 | { |
58 | package Bar; |
59 | |
60 | Foo->import(); |
61 | |
748d15e6 |
62 | ::stderr_like{ Foo::foo() } |
63 | qr/\Qfoo is deprecated/, |
dc4fc8c7 |
64 | 'deprecation warning for foo'; |
65 | |
748d15e6 |
66 | ::stderr_like{ Foo::bar() } |
67 | qr/\Qbar is deprecated/, |
dc4fc8c7 |
68 | 'deprecation warning for bar'; |
69 | |
748d15e6 |
70 | ::stderr_like{ Foo::baz() } |
71 | qr/\QFoo::baz has been deprecated since version 1.21/, |
dc4fc8c7 |
72 | 'deprecation warning for baz, and message is generated by Package::DeprecationManager'; |
73 | |
748d15e6 |
74 | ::stderr_is{ Foo::foo() } q{}, 'no warning on second call to foo'; |
dc4fc8c7 |
75 | |
748d15e6 |
76 | ::stderr_is{ Foo::bar() } q{}, 'no warning on second call to bar'; |
dc4fc8c7 |
77 | |
748d15e6 |
78 | ::stderr_is{ Foo::baz() } q{}, 'no warning on second call to baz'; |
c9ed2327 |
79 | |
748d15e6 |
80 | ::stderr_like{ Foo::varies(1) } |
81 | qr/\QThe varies sub varies: 1/, |
c9ed2327 |
82 | 'warning for varies sub'; |
83 | |
748d15e6 |
84 | ::stderr_like{ Foo::varies(2) } |
85 | qr/\QThe varies sub varies: 2/, |
c9ed2327 |
86 | 'warning for varies sub with different error'; |
87 | |
748d15e6 |
88 | ::stderr_is{ Foo::varies(1) } |
c9ed2327 |
89 | q{}, |
90 | 'no warning for varies sub with same message as first call'; |
dc4fc8c7 |
91 | } |
92 | |
93 | { |
94 | package Baz; |
95 | |
96 | Foo->import( -api_version => '0.01' ); |
97 | |
748d15e6 |
98 | ::stderr_is{ Foo::foo() } |
dc4fc8c7 |
99 | q{}, |
100 | 'no warning for foo with api_version = 0.01'; |
101 | |
748d15e6 |
102 | ::stderr_is{ Foo::bar() } |
dc4fc8c7 |
103 | q{}, |
104 | 'no warning for bar with api_version = 0.01'; |
105 | |
748d15e6 |
106 | ::stderr_is{ Foo::baz() } |
dc4fc8c7 |
107 | q{}, |
108 | 'no warning for baz with api_version = 0.01'; |
109 | } |
110 | |
dc4fc8c7 |
111 | { |
112 | package Quux; |
113 | |
114 | Foo->import( -api_version => '1.17' ); |
115 | |
748d15e6 |
116 | ::stderr_like{ Foo::foo() } |
117 | qr/\Qfoo is deprecated/, |
dc4fc8c7 |
118 | 'deprecation warning for foo with api_version = 1.17'; |
119 | |
748d15e6 |
120 | ::stderr_like{ Foo::bar() } |
121 | qr/\Qbar is deprecated/, |
dc4fc8c7 |
122 | 'deprecation warning for bar with api_version = 1.17'; |
123 | |
748d15e6 |
124 | ::stderr_is{ Foo::baz() } |
dc4fc8c7 |
125 | q{}, |
126 | 'no warning for baz with api_version = 1.17'; |
127 | } |
128 | |
bce3492c |
129 | { |
130 | package Another; |
131 | |
132 | Foo->import(); |
133 | |
748d15e6 |
134 | ::stderr_is{ Foo::quux(1) } |
bce3492c |
135 | q{}, |
136 | 'no warning for quux(1)'; |
137 | |
748d15e6 |
138 | ::stderr_like{ Foo::quux(10) } |
139 | qr/\Qquux > 5 has been deprecated/, |
bce3492c |
140 | 'got a warning for quux(10)'; |
141 | } |
142 | |
d26afdef |
143 | |
144 | { |
145 | package Dep; |
146 | |
147 | use Package::DeprecationManager -deprecations => { |
748d15e6 |
148 | 'Dep::foo' => '1.00', |
d26afdef |
149 | }, |
37bcd4f7 |
150 | -ignore => [ 'My::Package1', 'My::Package2' ]; |
d26afdef |
151 | |
152 | sub foo { |
153 | deprecated('foo is deprecated'); |
154 | } |
155 | } |
156 | |
157 | { |
37bcd4f7 |
158 | package Dep2; |
159 | |
160 | use Package::DeprecationManager -deprecations => { |
748d15e6 |
161 | 'Dep2::bar' => '1.00', |
37bcd4f7 |
162 | }, |
748d15e6 |
163 | -ignore => [ qr/My::Package[12]/ ]; |
37bcd4f7 |
164 | |
165 | sub bar { |
166 | deprecated('bar is deprecated'); |
167 | } |
168 | } |
169 | |
170 | { |
171 | package My::Package1; |
d26afdef |
172 | |
173 | sub foo { Dep::foo() } |
37bcd4f7 |
174 | sub bar { Dep2::bar() } |
d26afdef |
175 | } |
176 | |
177 | { |
37bcd4f7 |
178 | package My::Package2; |
d26afdef |
179 | |
37bcd4f7 |
180 | sub foo { My::Package1::foo() } |
181 | sub bar { My::Package1::bar() } |
d26afdef |
182 | } |
183 | |
184 | { |
185 | package My::Baz; |
186 | |
748d15e6 |
187 | ::stderr_like{ My::Package2::foo() } |
188 | qr/^foo is deprecated at t.basic\.t line \d+\s+My::Baz/, |
189 | 'deprecation warning for call to My::Package2::foo() and mentions My::Baz but not My::Package[12]'; |
190 | |
191 | ::stderr_is{ My::Package2::foo() } |
192 | q{}, |
193 | 'no deprecation warning for second call to My::Package2::foo()'; |
194 | |
195 | ::stderr_is{ My::Package1::foo() } |
196 | q{}, |
197 | 'no deprecation warning for call to My::Package1::foo()'; |
e546f61d |
198 | |
748d15e6 |
199 | ::stderr_like{ My::Package2::bar() } |
200 | qr/^bar is deprecated at t.basic\.t line \d+\s+My::Baz/, |
201 | 'deprecation warning for call to My::Package2::foo() and mentions My::Baz but not My::Package[12]'; |
37bcd4f7 |
202 | |
748d15e6 |
203 | ::stderr_is{ My::Package2::bar() } |
204 | q{}, |
205 | 'no deprecation warning for second call to My::Package2::bar()'; |
d26afdef |
206 | } |
207 | |
208 | { |
748d15e6 |
209 | package My::Quux; |
d26afdef |
210 | |
748d15e6 |
211 | ::stderr_like{ My::Package1::foo() } |
212 | qr/^foo is deprecated at t.basic\.t line \d+\s+My::Quux/, |
213 | 'deprecation warning for call to My::Package1::foo() and mentions My::Quux but not My::Package[12]'; |
d26afdef |
214 | |
748d15e6 |
215 | ::stderr_is{ My::Package1::foo() } |
d26afdef |
216 | q{}, |
748d15e6 |
217 | 'no deprecation warning for second call to My::Package1::foo()'; |
d26afdef |
218 | } |
219 | |
dc4fc8c7 |
220 | done_testing(); |