From: Chia-liang Kao Date: Wed, 15 Jun 2011 03:28:46 +0000 (+0800) Subject: tests for redefined subroutine warnings. X-Git-Tag: 0.006005~1^2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=62067fd996e725821f9ca325b288ee6b61de375f;p=p5sagit%2FDevel-Declare.git tests for redefined subroutine warnings. --- diff --git a/Makefile.PL b/Makefile.PL index dd795f6..b698c36 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -21,6 +21,7 @@ configure_requires 'ExtUtils::Depends' => 0.302; configure_requires 'B::Hooks::OP::Check' => '0.18'; test_requires 'Test::More' => '0.88'; +test_requires 'Test::Warn'; repository 'git://github.com/rafl/devel-declare.git'; diff --git a/t/method-installer-redefine.t b/t/method-installer-redefine.t new file mode 100644 index 0000000..742728f --- /dev/null +++ b/t/method-installer-redefine.t @@ -0,0 +1,42 @@ +use strict; +use warnings; +use Test::More tests => 4; +use Test::Warn; +use Devel::Declare::MethodInstaller::Simple; + +BEGIN { + Devel::Declare::MethodInstaller::Simple->install_methodhandler( + name => 'method', + into => 'main', + ); +} + +BEGIN { + no warnings 'redefine'; + Devel::Declare::MethodInstaller::Simple->install_methodhandler( + name => 'method_quiet', + into => 'main', + ); +} + +ok(!main->can('foo'), 'foo() not installed yet'); + +method foo { + $_[0]->method +} + +use Test::Warn; + +ok(main->can('foo'), 'foo() installed at runtime'); + +warnings_like { + method foo { + $_[0]->method; + } +} qr/redefined/; + +warnings_are { + method_quiet foo { + $_[0]->method; + } +} [], 'no warnings';