Here's a patch to the Test::Simple 0.45 distribution to make isa_ok() work with
class names, not just objects. It tries to respect custom isa() methods, as
well.
-- c
diff -ur Test-Simple-0.45.old/lib/Test/More.pm Test-Simple-0.45/lib/Test/More.pm
--- Test-Simple-0.45.old/lib/Test/More.pm Wed Jun 19 14:45:52 2002
+++ Test-Simple-0.45/lib/Test/More.pm Sun Jun 30 17:05:09 2002
@@ -522,7 +522,13 @@
$diag = "$obj_name isn't defined";
}
elsif( !ref $object ) {
- $diag = "$obj_name isn't a reference";
+ local $@;
+ if (my $isa = eval{ $object->can( 'isa' ) }) {
+ $isa->( $object, $class )
+ or $diag = "$obj_name isn't a $class";
+ } else {
+ $diag = "$obj_name isn't a reference or a class";
+ }
}
else {
# We can't use UNIVERSAL::isa because we want to honor isa() overrides
diff -ur Test-Simple-0.45.old/t/More.t Test-Simple-0.45/t/More.t
--- Test-Simple-0.45.old/t/More.t Sat Apr 20 17:34:40 2002
+++ Test-Simple-0.45/t/More.t Sun Jun 30 17:02:46 2002
@@ -7,7 +7,7 @@
}
}
-use Test::More tests => 41;
+use Test::More tests => 42;
# Make sure we don't mess with $@ or $!. Test at bottom.
my $Err = "this should not be touched";
@@ -59,6 +59,14 @@
isa_ok( $foo, 'blah');
}
+# isa_ok() should handle classes, as well
+{
+ package Bar;
+ package Foo;
+ @Foo::ISA = 'Bar';
+ package main;
+ isa_ok( 'Foo', 'Bar' );
+}
pass('pass() passed');
diff -ur Test-Simple-0.45.old/t/fail-more.t Test-Simple-0.45/t/fail-more.t
--- Test-Simple-0.45.old/t/fail-more.t Mon Jan 21 11:33:53 2002
+++ Test-Simple-0.45/t/fail-more.t Sun Jun 30 17:07:52 2002
@@ -167,7 +167,7 @@
# Failed test ($0 at line 55)
# The object isn't a 'Wibble' it's a 'Foo'
# Failed test ($0 at line 56)
-# My Wibble isn't a reference
+# My Wibble isn't a reference or a class
# Failed test ($0 at line 57)
# Another Wibble isn't defined
# Failed test ($0 at line 58)