File: basic.t

package info (click to toggle)
libpackage-deprecationmanager-perl 0.17-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 288 kB
  • ctags: 4
  • sloc: perl: 323; makefile: 2
file content (275 lines) | stat: -rw-r--r-- 5,858 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
use strict;
use warnings;

use Test::More 0.88;
use Test::Fatal;
use Test::Warnings qw( warning warnings );

{
    ## no critic (BuiltinFunctions::ProhibitStringyEval, ErrorHandling::RequireCheckingReturnValueOfEval)
    like(
        exception {
            eval 'package Whatever; use Package::DeprecationManager;';
            die $@ if $@;
        },
        qr/^\QYou must provide a hash reference -deprecations parameter when importing Package::DeprecationManager/,
        'must provide a set of deprecations when using Package::DeprecationManager'
    );
}

## no critic (Modules::ProhibitMultiplePackages)

{
    package Foo;

    use Package::DeprecationManager -deprecations => {
        'Foo::foo'  => '0.02',
        'Foo::bar'  => '0.03',
        'Foo::baz'  => '1.21',
        'not a sub' => '1.23',
    };

    sub foo {
        deprecated('foo is deprecated');
    }

    sub bar {
        deprecated('bar is deprecated');
    }

    sub baz {
        deprecated();
    }

    sub quux {
        if ( $_[0] > 5 ) {
            deprecated(
                message => 'quux > 5 has been deprecated',
                feature => 'not a sub',
            );
        }
    }

    sub varies {
        deprecated("The varies sub varies: $_[0]");
    }

}

{
    package Bar;

    Foo->import();

    ::like(
        ::warning { Foo::foo() },
        qr/\Qfoo is deprecated/,
        'deprecation warning for foo'
    );

    ::like(
        ::warning { Foo::bar() },
        qr/\Qbar is deprecated/,
        'deprecation warning for bar'
    );

    ::like(
        ::warning { Foo::baz() },
        qr/\QFoo::baz has been deprecated since version 1.21/,
        'deprecation warning for baz, and message is generated by Package::DeprecationManager'
    );

    ::is_deeply(
        [ ::warnings { Foo::foo() } ],
        [],
        'no warning on second call to foo'
    );

    ::is_deeply(
        [ ::warnings { Foo::bar() } ],
        [],
        'no warning on second call to bar'
    );

    ::is_deeply(
        [ ::warnings { Foo::baz() } ],
        [],
        'no warning on second call to baz'
    );

    ::like(
        ::warning { Foo::varies(1) },
        qr/\QThe varies sub varies: 1/,
        'warning for varies sub'
    );

    ::like(
        ::warning { Foo::varies(2) },
        qr/\QThe varies sub varies: 2/,
        'warning for varies sub with different error'
    );

    ::is_deeply(
        [ ::warnings { Foo::varies(1) } ],
        [],
        'no warning for varies sub with same message as first call'
    );
}

{
    package Baz;

    Foo->import( -api_version => '0.01' );

    ::is_deeply(
        [ ::warnings { Foo::foo() } ],
        [],
        'no warning for foo with api_version = 0.01'
    );

    ::is_deeply(
        [ ::warnings { Foo::bar() } ],
        [],
        'no warning for bar with api_version = 0.01'
    );

    ::is_deeply(
        [ ::warnings { Foo::baz() } ],
        [],
        'no warning for baz with api_version = 0.01'
    );
}

{
    package Quux;

    Foo->import( -api_version => '1.17' );

    ::like(
        ::warning { Foo::foo() },
        qr/\Qfoo is deprecated/,
        'deprecation warning for foo with api_version = 1.17'
    );

    ::like(
        ::warning { Foo::bar() },
        qr/\Qbar is deprecated/,
        'deprecation warning for bar with api_version = 1.17'
    );

    ::is_deeply(
        [ ::warnings { Foo::baz() } ],
        [],
        'no warning for baz with api_version = 1.17'
    );
}

{
    package Another;

    Foo->import();

    ::is_deeply(
        [ ::warnings { Foo::quux(1) } ],
        [],
        'no warning for quux(1)'
    );

    ::like(
        ::warning { Foo::quux(10) },
        qr/\Qquux > 5 has been deprecated/,
        'got a warning for quux(10)'
    );
}

{
    package Dep;

    use Package::DeprecationManager -deprecations => {
        'Dep::foo' => '1.00',
        },
        -ignore => [ 'My::Package1', 'My::Package2' ];

    sub foo {
        deprecated('foo is deprecated');
    }
}

{
    package Dep2;

    use Package::DeprecationManager -deprecations => {
        'Dep2::bar' => '1.00',
        },
        -ignore => [qr/My::Package[12]/];

    sub bar {
        deprecated('bar is deprecated');
    }
}

{
    package My::Package1;

    sub foo { Dep::foo() }
    sub bar { Dep2::bar() }
}

{
    package My::Package2;

    sub foo { My::Package1::foo() }
    sub bar { My::Package1::bar() }
}

{
    package My::Baz;

    ::like(
        ::warning { My::Package2::foo() },
        qr/^foo is deprecated at t.basic\.t line \d+\.?\s+My::Baz/,
        'deprecation warning for call to My::Package2::foo() and mentions My::Baz but not My::Package[12]'
    );

    ::is_deeply(
        [ ::warnings { My::Package2::foo() } ],
        [],
        'no deprecation warning for second call to My::Package2::foo()'
    );

    ::is_deeply(
        [ ::warnings { My::Package1::foo() } ],
        [],
        'no deprecation warning for call to My::Package1::foo()'
    );

    ::like(
        ::warning { My::Package2::bar() },
        qr/^bar is deprecated at t.basic\.t line \d+\.?\s+My::Baz/,
        'deprecation warning for call to My::Package2::foo() and mentions My::Baz but not My::Package[12]'
    );

    ::is_deeply(
        [ ::warnings { My::Package2::bar() } ],
        [],
        'no deprecation warning for second call to My::Package2::bar()'
    );
}

{
    package My::Quux;

    ::like(
        ::warning { My::Package1::foo() },
        qr/^foo is deprecated at t.basic\.t line \d+\.?\s+My::Quux/,
        'deprecation warning for call to My::Package1::foo() and mentions My::Quux but not My::Package[12]'
    );

    ::is_deeply(
        [ ::warnings { My::Package1::foo() } ],
        [],
        'no deprecation warning for second call to My::Package1::foo()'
    );
}

done_testing();