Subject: | Fix blessed.t for Test::Builder2 |
t/blessed.t breaks UNIVERSAL::can. This will break future versions of
Test::More whose test versions will rely on can() and it's probably a
bad idea in general.
The attached patch moves the UNIVERSAL::can bits into its own file which
doesn't use a test library.
Subject: | 0001-Fix-the-tests-for-blessed-so-they-don-t-break-Test-M.patch |
From 34a59e5bf40c0b43cc1f29d7263d27faf06ab1ac Mon Sep 17 00:00:00 2001
From: "Michael G. Schwern" <schwern@pobox.com>
Date: Fri, 30 Mar 2012 18:52:36 +0200
Subject: [PATCH] Fix the tests for blessed() so they don't break Test::More.
Test::More might need UNIVERSAL::can, which blessed.t breaks. Move the
bit that breaks UNIVERSAL::can into its own file which doesn't use a
test library.
---
t/blessed.t | 12 +-----------
t/blessed_UNIVERSAL_can.t | 30 ++++++++++++++++++++++++++++++
2 files changed, 31 insertions(+), 11 deletions(-)
create mode 100644 t/blessed_UNIVERSAL_can.t
diff --git a/t/blessed.t b/t/blessed.t
index f0a4c19..1925297 100644
--- a/t/blessed.t
+++ b/t/blessed.t
@@ -13,7 +13,7 @@ BEGIN {
}
}
-use Test::More tests => 11;
+use Test::More tests => 10;
use Scalar::Util qw(blessed);
use vars qw($t $x);
@@ -34,16 +34,6 @@ $x = bless {}, "0";
cmp_ok(blessed($x), "eq", "0", 'blessed HASH-ref');
{
- my $depth;
- {
- no warnings 'redefine';
- *UNIVERSAL::can = sub { die "Burp!" if ++$depth > 2; blessed(shift) };
- }
- $x = bless {}, "DEF";
- is(blessed($x), "DEF", 'recursion of UNIVERSAL::can');
-}
-
-{
package Broken;
sub isa { die };
sub can { die };
diff --git a/t/blessed_UNIVERSAL_can.t b/t/blessed_UNIVERSAL_can.t
new file mode 100644
index 0000000..5a58ad3
--- /dev/null
+++ b/t/blessed_UNIVERSAL_can.t
@@ -0,0 +1,30 @@
+#!./perl
+
+BEGIN {
+ unless (-d 'blib') {
+ chdir 't' if -d 't';
+ @INC = '../lib';
+ require Config; import Config;
+ keys %Config; # Silence warning
+ if ($Config{extensions} !~ /\bList\/Util\b/) {
+ print "1..0 # Skip: List::Util was not built\n";
+ exit 0;
+ }
+ }
+}
+
+use Scalar::Util qw(blessed);
+
+# Can't use a test library, we're going to break UNIVERSAL::can
+print "1..1\n";
+{
+ my $depth;
+ {
+ no warnings 'redefine';
+ *UNIVERSAL::can = sub { die "Burp!" if ++$depth > 2; blessed(shift) };
+ }
+
+ my $x = bless {}, "DEF";
+ my $ok = blessed($x) eq "DEF" ? "ok" : "not ok";
+ print "$ok 1 - recursion of UNIVERSAL::can\n";
+}
--
1.7.9.4