tests for redefined subroutine warnings.
Chia-liang Kao [Wed, 15 Jun 2011 03:28:46 +0000 (11:28 +0800)]
Makefile.PL
t/method-installer-redefine.t [new file with mode: 0644]

index dd795f6..b698c36 100644 (file)
@@ -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 (file)
index 0000000..742728f
--- /dev/null
@@ -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';