From: Dave Rolsky Date: Fri, 15 Oct 2010 01:24:36 +0000 (-0500) Subject: Fix handling of ignore regexes and test them properly X-Git-Tag: v0.07~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=748d15e670b8133acebb18c57b586d59afc9fdb8;p=gitmo%2FPackage-DeprecationManager.git Fix handling of ignore regexes and test them properly --- diff --git a/lib/Package/DeprecationManager.pm b/lib/Package/DeprecationManager.pm index ba85924..a79f19c 100644 --- a/lib/Package/DeprecationManager.pm +++ b/lib/Package/DeprecationManager.pm @@ -75,7 +75,7 @@ sub _build_warn { my $skipped = 1; - if ( keys %ignore ) { + if ( @ignore_res || keys %ignore ) { while ( defined $package && ( $ignore{$package} || any { $package =~ $_ } @ignore_res ) ) { diff --git a/t/basic.t b/t/basic.t index fdf4140..90da5f9 100644 --- a/t/basic.t +++ b/t/basic.t @@ -5,7 +5,7 @@ use Test::Exception; use Test::More; use Test::Requires { - 'Test::Warn' => '0.21', + 'Test::Output' => '0.16', }; { @@ -59,33 +59,33 @@ use Test::Requires { 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'; - ::warning_is{ Foo::bar() } q{}, 'no warning on second call to bar'; + ::stderr_is{ Foo::bar() } q{}, 'no warning on second call to bar'; - ::warning_is{ Foo::baz() } q{}, 'no warning on second call to baz'; + ::stderr_is{ Foo::baz() } q{}, 'no warning on second call to baz'; - ::warning_is{ Foo::varies(1) } - { carped => "The varies sub varies: 1" }, + ::stderr_like{ Foo::varies(1) } + qr/\QThe varies sub varies: 1/, 'warning for varies sub'; - ::warning_is{ Foo::varies(2) } - { carped => "The varies sub varies: 2" }, + ::stderr_like{ Foo::varies(2) } + qr/\QThe varies sub varies: 2/, 'warning for varies sub with different error'; - ::warning_is{ Foo::varies(1) } + ::stderr_is{ Foo::varies(1) } q{}, 'no warning for varies sub with same message as first call'; } @@ -95,15 +95,15 @@ use Test::Requires { 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'; } @@ -113,15 +113,15 @@ use Test::Requires { 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'; } @@ -131,12 +131,12 @@ use Test::Requires { 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)'; } @@ -145,7 +145,7 @@ use Test::Requires { package Dep; use Package::DeprecationManager -deprecations => { - 'foo' => '1.00', + 'Dep::foo' => '1.00', }, -ignore => [ 'My::Package1', 'My::Package2' ]; @@ -158,9 +158,9 @@ use Test::Requires { package Dep2; use Package::DeprecationManager -deprecations => { - 'bar' => '1.00', + 'Dep2::bar' => '1.00', }, - -ignore => [ 'My::Package2' ]; + -ignore => [ qr/My::Package[12]/ ]; sub bar { deprecated('bar is deprecated'); @@ -168,24 +168,10 @@ use Test::Requires { } { - package Dep3; - - use Package::DeprecationManager -deprecations => { - 'baz' => '1.00', - }, - -ignore => [ qr/My::Package[12]/ ]; - - sub baz { - deprecated('baz is deprecated'); - } -} - -{ package My::Package1; sub foo { Dep::foo() } sub bar { Dep2::bar() } - sub baz { Dep3::baz() } } { @@ -193,33 +179,42 @@ use Test::Requires { sub foo { My::Package1::foo() } sub bar { My::Package1::bar() } - sub baz { My::Package1::baz() } } { package My::Baz; - ::warning_like{ My::Package1::bar() } - qr/^bar is deprecated at t.basic\.t line \d+/, - 'deprecation warning for call to My::Package1::bar()'; + ::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()'; - ::warning_like{ My::Package2::foo() } - qr/^foo is deprecated at t.basic\.t line \d+/, - 'deprecation warning for call to My::Package2::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]'; - ::warning_like{ My::Package1::baz() } - qr/^baz is deprecated at t.basic\.t line \d+/, - 'deprecation warning for call to My::Package2::foo()'; + ::stderr_is{ My::Package2::bar() } + q{}, + 'no deprecation warning for second call to My::Package2::bar()'; } { - package My::Baz; + package My::Quux; - Dep->import( -api_version => '0.8' ); + ::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]'; - ::warning_is{ My::Package2::foo() } + ::stderr_is{ My::Package1::foo() } q{}, - 'no warning when calling My::Package2::foo()'; + 'no deprecation warning for second call to My::Package1::foo()'; } done_testing();