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