X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fbasic.t;h=20e6e5d2b3acbaa8941373eb1d08c9ff1bb33436;hb=eb17fbd4c32b13bbcc6d32e6bf2ac78092d44779;hp=107020d49593a48e0269c787139bf79bde5e9ac1;hpb=bce3492c6adff8c9cd36571356012f8e1c109aee;p=gitmo%2FPackage-DeprecationManager.git diff --git a/t/basic.t b/t/basic.t index 107020d..20e6e5d 100644 --- a/t/basic.t +++ b/t/basic.t @@ -1,17 +1,22 @@ use strict; use warnings; -use Test::Exception; use Test::More; -use Test::Warn; +use Test::Fatal; + +use Test::Requires { + 'Test::Output' => '0.16', +}; { - throws_ok { - eval 'package Foo; 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'; + like( + exception { + eval 'package Foo; 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' + ); } { @@ -44,6 +49,11 @@ use Test::Warn; ); } } + + sub varies { + deprecated("The varies sub varies: $_[0]"); + } + } { @@ -51,23 +61,35 @@ use Test::Warn; Foo->import(); - ::warning_is{ Foo::foo() } - { carped => 'foo is deprecated' }, + ::stderr_like{ Foo::foo() } + qr/\Qfoo is deprecated/, 'deprecation warning for foo'; - ::warning_is{ Foo::bar() } - { carped => 'bar is deprecated' }, + ::stderr_like{ Foo::bar() } + qr/\Qbar is deprecated/, 'deprecation warning for bar'; - ::warning_is{ Foo::baz() } - { carped => 'Foo::baz has been deprecated since version 1.21' }, + ::stderr_like{ Foo::baz() } + qr/\QFoo::baz has been deprecated since version 1.21/, 'deprecation warning for baz, and message is generated by Package::DeprecationManager'; - ::warning_is{ Foo::foo() } q{}, 'no warning on second call to foo'; + ::stderr_is{ Foo::foo() } q{}, 'no warning on second call to foo'; + + ::stderr_is{ Foo::bar() } q{}, 'no warning on second call to bar'; + + ::stderr_is{ Foo::baz() } q{}, 'no warning on second call to baz'; - ::warning_is{ Foo::bar() } q{}, 'no warning on second call to bar'; + ::stderr_like{ Foo::varies(1) } + qr/\QThe varies sub varies: 1/, + 'warning for varies sub'; - ::warning_is{ Foo::baz() } q{}, 'no warning on second call to baz'; + ::stderr_like{ Foo::varies(2) } + qr/\QThe varies sub varies: 2/, + 'warning for varies sub with different error'; + + ::stderr_is{ Foo::varies(1) } + q{}, + 'no warning for varies sub with same message as first call'; } { @@ -75,15 +97,15 @@ use Test::Warn; Foo->import( -api_version => '0.01' ); - ::warning_is{ Foo::foo() } + ::stderr_is{ Foo::foo() } q{}, 'no warning for foo with api_version = 0.01'; - ::warning_is{ Foo::bar() } + ::stderr_is{ Foo::bar() } q{}, 'no warning for bar with api_version = 0.01'; - ::warning_is{ Foo::baz() } + ::stderr_is{ Foo::baz() } q{}, 'no warning for baz with api_version = 0.01'; } @@ -93,15 +115,15 @@ use Test::Warn; Foo->import( -api_version => '1.17' ); - ::warning_is{ Foo::foo() } - { carped => 'foo is deprecated' }, + ::stderr_like{ Foo::foo() } + qr/\Qfoo is deprecated/, 'deprecation warning for foo with api_version = 1.17'; - ::warning_is{ Foo::bar() } - { carped => 'bar is deprecated' }, + ::stderr_like{ Foo::bar() } + qr/\Qbar is deprecated/, 'deprecation warning for bar with api_version = 1.17'; - ::warning_is{ Foo::baz() } + ::stderr_is{ Foo::baz() } q{}, 'no warning for baz with api_version = 1.17'; } @@ -111,13 +133,90 @@ use Test::Warn; Foo->import(); - ::warning_is{ Foo::quux(1) } + ::stderr_is{ Foo::quux(1) } q{}, 'no warning for quux(1)'; - ::warning_is{ Foo::quux(10) } - { carped => 'quux > 5 has been deprecated' }, + ::stderr_like{ 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; + + ::stderr_like{ 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]'; + + ::stderr_is{ My::Package2::foo() } + q{}, + 'no deprecation warning for second call to My::Package2::foo()'; + + ::stderr_is{ My::Package1::foo() } + q{}, + 'no deprecation warning for call to My::Package1::foo()'; + + ::stderr_like{ 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]'; + + ::stderr_is{ My::Package2::bar() } + q{}, + 'no deprecation warning for second call to My::Package2::bar()'; +} + +{ + package My::Quux; + + ::stderr_like{ 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]'; + + ::stderr_is{ My::Package1::foo() } + q{}, + 'no deprecation warning for second call to My::Package1::foo()'; +} + done_testing();