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
|
use strict;
use warnings;
use Test::More tests => 5;
{
package test::dancer::deprecated;
use base 'Dancer::Object';
use Dancer::Deprecation;
sub foo {
Dancer::Deprecation->deprecated(
feature => 'foo',
version => '0.1',
message => 'calling foo is deprecated, you should use bar',
);
}
sub bar {
Dancer::Deprecation->deprecated(
'calling bar is also deprecated, you should use baz');
}
sub baz {
Dancer::Deprecation->deprecated();
}
sub foo_bar_baz {
Dancer::Deprecation->deprecated(
version => '0.1',
feature => 'foo_bar_baz',
);
}
sub fatal {
Dancer::Deprecation->deprecated(
message => 'this should die',
fatal => 1,
);
}
}
my $warn;
local $SIG{__WARN__} = sub { $warn = $_[0] };
my $t = test::dancer::deprecated->new();
$t->foo();
like $warn, qr/calling foo is deprecated, you should use bar since version 0.1/,
'deprecation with feature, message and version';
$warn = undef;
$t->bar();
like $warn, qr/test::dancer::deprecated::bar has been deprecated/,
'deprecation with only message';
$warn = undef;
$t->baz();
like $warn, qr/test::dancer::deprecated::baz has been deprecated/,
'deprecation with default message';
$warn = undef;
$t->foo_bar_baz();
like $warn, qr/foo_bar_baz has been deprecated since version 0.1/,
'deprecation with feature and version';
eval {$t->fatal};
like $@, qr/this should die/;
|