Change every existing instance of isa_ok() to use object_ok(). This is safe because
before this point, t/test.pl's isa_ok() only worked on objects. lib/dbmt_common.pl is
the last hold out because it uses Test::More.
These are like isa_ok() but they also check if it's a class or an object.
This lets the core tests defend against outlandish bugs while allowing
t/test.pl to retain feature parity with Test::More.
$ps = svref_2object(\*{"Fcntl::$symbol"});
$ms = svref_2object(\*{"::$symbol"});
}
- isa_ok($ps, 'B::GV');
+ object_ok($ps, 'B::GV');
is($ps->GvFLAGS() & GVf_IMPORTED_CV, 0,
"GVf_IMPORTED_CV not set on original");
- isa_ok($ms, 'B::GV');
+ object_ok($ms, 'B::GV');
is($ms->GvFLAGS() & GVf_IMPORTED_CV, GVf_IMPORTED_CV,
"GVf_IMPORTED_CV set on imported GV");
}
}
my $x = InheritingFromOverloadedTest->new();
-isa_ok($x, 'InheritingFromOverloadedTest');
+object_ok($x, 'InheritingFromOverloadedTest');
my $y = OverloadingTest->new();
-isa_ok($y, 'OverloadingTest');
+object_ok($y, 'OverloadingTest');
is("$x", 'InheritingFromOverloadedTest stringified', '... got the right value when stringifing');
is("$y", 'OverloadingTest stringified', '... got the right value when stringifing');
}
my $x = InheritingFromOverloadedTest->new();
-isa_ok($x, 'InheritingFromOverloadedTest');
+object_ok($x, 'InheritingFromOverloadedTest');
my $y = OverloadingTest->new();
-isa_ok($y, 'OverloadingTest');
+object_ok($y, 'OverloadingTest');
is("$x", 'InheritingFromOverloadedTest stringified', '... got the right value when stringifing');
is("$y", 'OverloadingTest stringified', '... got the right value when stringifing');
is("@{mro::get_linear_isa($package)}", "@$isa", "\@ISA for $package");
foreach my $class ($package, @$isa, 'UNIVERSAL') {
- isa_ok($ref, $class, $package);
+ object_ok($ref, $class, $package);
}
}
is("@{mro::get_linear_isa($package)}", "@$isa", "\@ISA for $package");
foreach my $class ($package, @$isa, 'UNIVERSAL') {
- isa_ok($ref, $class, $package);
+ object_ok($ref, $class, $package);
}
}
is("@{mro::get_linear_isa($package)}", "@$isa", "\@ISA for $package");
foreach my $class ($package, @$isa, 'UNIVERSAL') {
- isa_ok($ref, $class, $package);
+ object_ok($ref, $class, $package);
}
}
is("@{mro::get_linear_isa($package)}", "@$isa", "\@ISA for $package");
foreach my $class ($package, @$isa, 'UNIVERSAL') {
- isa_ok($ref, $class, $package);
+ object_ok($ref, $class, $package);
}
}
# call the submethod in the direct instance
my $foo = Foo->new();
- isa_ok($foo, 'Foo');
+ object_ok($foo, 'Foo');
can_ok($foo, 'bar');
is($foo->bar(), 'Foo::bar', '... got the right return value');
}
my $bar = Bar->new();
- isa_ok($bar, 'Bar');
- isa_ok($bar, 'Foo');
+ object_ok($bar, 'Bar');
+ object_ok($bar, 'Foo');
# test it working with with Sub::Name
SKIP: {
}
my $baz = Baz->new();
- isa_ok($baz, 'Baz');
- isa_ok($baz, 'Foo');
+ object_ok($baz, 'Baz');
+ object_ok($baz, 'Foo');
{
my $m = sub { (shift)->next::method() };
# call the submethod in the direct instance
my $foo = ᕘ->new();
- isa_ok($foo, 'ᕘ');
+ object_ok($foo, 'ᕘ');
can_ok($foo, 'ƚ');
is($foo->ƚ(), 'ᕘ::ƚ', '... got the right return value');
}
my $bar = Baɾ->new();
- isa_ok($bar, 'Baɾ');
- isa_ok($bar, 'ᕘ');
+ object_ok($bar, 'Baɾ');
+ object_ok($bar, 'ᕘ');
# test it working with with Sub::Name
SKIP: {
}
my $baz = બʑ->new();
- isa_ok($baz, 'બʑ');
- isa_ok($baz, 'ᕘ');
+ object_ok($baz, 'બʑ');
+ object_ok($baz, 'ᕘ');
{
my $m = sub { (shift)->next::method() };
}
my $x = InheritingFromOverloadedTest->new();
-isa_ok($x, 'InheritingFromOverloadedTest');
+object_ok($x, 'InheritingFromOverloadedTest');
my $y = OverloadingTest->new();
-isa_ok($y, 'OverloadingTest');
+object_ok($y, 'OverloadingTest');
is("$x", 'InheritingFromOverloadedTest stringified', '... got the right value when stringifing');
is("$y", 'OverloadingTest stringified', '... got the right value when stringifing');
}
my $x = 읺ҎꀀḮṆᵷꜰ롬ᵕveŔŁoad엗텟ᵵ->ネᚹ();
-isa_ok($x, '읺ҎꀀḮṆᵷꜰ롬ᵕveŔŁoad엗텟ᵵ');
+object_ok($x, '읺ҎꀀḮṆᵷꜰ롬ᵕveŔŁoad엗텟ᵵ');
my $y = Ov에rꪩࡃᛝTeŝṱ->ネᚹ();
-isa_ok($y, 'Ov에rꪩࡃᛝTeŝṱ');
+object_ok($y, 'Ov에rꪩࡃᛝTeŝṱ');
is("$x", '읺ҎꀀḮṆᵷꜰ롬ᵕveŔŁoad엗텟ᵵ stringified', '... got the right value when stringifing');
is("$y", 'Ov에rꪩࡃᛝTeŝṱ stringified', '... got the right value when stringifing');
}
my $x = InheritingFromOverloadedTest->new();
-isa_ok($x, 'InheritingFromOverloadedTest');
+object_ok($x, 'InheritingFromOverloadedTest');
my $y = OverloadingTest->new();
-isa_ok($y, 'OverloadingTest');
+object_ok($y, 'OverloadingTest');
is("$x", 'InheritingFromOverloadedTest stringified', '... got the right value when stringifing');
is("$y", 'OverloadingTest stringified', '... got the right value when stringifing');
ok (Old->isa (New::), 'Old inherits from New');
ok (New->isa (Old::), 'New inherits from Old');
-isa_ok (bless ({}, Old::), New::, 'Old object');
-isa_ok (bless ({}, New::), Old::, 'New object');
+object_ok (bless ({}, Old::), New::, 'Old object');
+object_ok (bless ({}, New::), Old::, 'New object');
# Test that replacing a package by assigning to an existing glob
ok (ऑlㄉ->isa(Neẁ::), 'ऑlㄉ inherits from Neẁ');
ok (Neẁ->isa(ऑlㄉ::), 'Neẁ inherits from ऑlㄉ');
-isa_ok (bless ({}, ऑlㄉ::), Neẁ::, 'ऑlㄉ object');
-isa_ok (bless ({}, Neẁ::), ऑlㄉ::, 'Neẁ object');
+object_ok (bless ({}, ऑlㄉ::), Neẁ::, 'ऑlㄉ object');
+object_ok (bless ({}, Neẁ::), ऑlㄉ::, 'Neẁ object');
# Test that replacing a package by assigning to an existing glob
}
my $a = r();
-isa_ok($a, 'Regexp');
+object_ok($a, 'Regexp');
my $b = r();
-isa_ok($b, 'Regexp');
+object_ok($b, 'Regexp');
my $b1 = $b;
bless $b, 'Pie';
-isa_ok($b, 'Pie');
-isa_ok($a, 'Regexp');
-isa_ok($b1, 'Pie');
+object_ok($b, 'Pie');
+object_ok($a, 'Regexp');
+object_ok($b1, 'Pie');
my $c = r();
like("$c", qr/Good/);
# Assignment to an implicitly blessed Regexp object retains the class
# (No different from direct value assignment to any other blessed SV
-isa_ok($d, 'Regexp');
+object_ok($d, 'Regexp');
like("$d", qr/\ARegexp=SCALAR\(0x[0-9a-f]+\)\z/);
# As does an explicitly blessed Regexp object.
my $e = bless qr/Faux Pie/, 'Stew';
-isa_ok($e, 'Stew');
+object_ok($e, 'Stew');
$$e = 'Fake!';
is($$e, 'Fake!');
-isa_ok($e, 'Stew');
+object_ok($e, 'Stew');
like("$e", qr/\Stew=SCALAR\(0x[0-9a-f]+\)\z/);
delete $one::{one};
my $gv = b($sub)->GV;
- isa_ok( $gv, "B::GV", "deleted stash entry leaves CV with valid GV");
+ object_ok( $gv, "B::GV", "deleted stash entry leaves CV with valid GV");
is( b($sub)->CvFLAGS & $CVf_ANON, $CVf_ANON, "...and CVf_ANON set");
is( eval { $gv->NAME }, "__ANON__", "...and an __ANON__ name");
is( eval { $gv->STASH->NAME }, "one", "...but leaves stash intact");
%two:: = ();
$gv = b($sub)->GV;
- isa_ok( $gv, "B::GV", "cleared stash leaves CV with valid GV");
+ object_ok( $gv, "B::GV", "cleared stash leaves CV with valid GV");
is( b($sub)->CvFLAGS & $CVf_ANON, $CVf_ANON, "...and CVf_ANON set");
is( eval { $gv->NAME }, "__ANON__", "...and an __ANON__ name");
is( eval { $gv->STASH->NAME }, "two", "...but leaves stash intact");
undef %three::;
$gv = b($sub)->GV;
- isa_ok( $gv, "B::GV", "undefed stash leaves CV with valid GV");
+ object_ok( $gv, "B::GV", "undefed stash leaves CV with valid GV");
is( b($sub)->CvFLAGS & $CVf_ANON, $CVf_ANON, "...and CVf_ANON set");
is( eval { $gv->NAME }, "__ANON__", "...and an __ANON__ name");
is( eval { $gv->STASH->NAME }, "__ANON__", "...and an __ANON__ stash");
(?<=[=&]) (?=.)
)}iox';
is($@, '', $message);
- isa_ok($r, 'Regexp', $message);
+ object_ok($r, 'Regexp', $message);
}
# RT #82610
}
-# Call $class->new( @$args ); and run the result through isa_ok.
+# Call $class->new( @$args ); and run the result through object_ok.
# See Test::More::new_ok
sub new_ok {
my($class, $args, $obj_name) = @_;
my $error = $@;
if($ok) {
- isa_ok($obj, $class, $object_name);
+ object_ok($obj, $class, $object_name);
}
else {
ok( 0, "new() died" );
_ok( !$diag, _where(), $name );
}
+
+sub class_ok {
+ my($class, $isa, $class_name) = @_;
+
+ # Written so as to count as one test
+ local $Level = $Level + 1;
+ if( ref $class ) {
+ ok( 0, "$class is a refrence, not a class name" );
+ }
+ else {
+ isa_ok($class, $isa, $class_name);
+ }
+}
+
+
+sub object_ok {
+ my($obj, $isa, $obj_name) = @_;
+
+ local $Level = $Level + 1;
+ if( !ref $obj ) {
+ ok( 0, "$obj is not a reference" );
+ }
+ else {
+ isa_ok($obj, $isa, $obj_name);
+ }
+}
+
+
# Purposefully avoiding a closure.
sub __capture {
push @::__capture, join "", @_;
use strict;
use warnings;
-BEGIN { require "t/test.pl"; }
+BEGIN { require "test.pl"; }
require Test::More;
}
+note "object/class_ok"; {
+ {
+ package Child;
+ our @ISA = qw(Parent);
+ }
+
+ {
+ package Parent;
+ sub new { bless {}, shift }
+ }
+
+ # Unfortunately we can't usefully test the failure case without
+ # significantly modifying test.pl
+ class_ok "Child", "Parent";
+ class_ok "Parent", "Parent";
+ object_ok( Parent->new, "Parent" );
+ object_ok( Child->new, "Parent" );
+}
+
done_testing;
delete $온ꪵ::{온ꪵ};
my $gv = b($sub)->GV;
- isa_ok( $gv, "B::GV", "deleted stash entry leaves CV with valid GV");
+ object_ok( $gv, "B::GV", "deleted stash entry leaves CV with valid GV");
is( b($sub)->CvFLAGS & $CVf_ANON, $CVf_ANON, "...and CVf_ANON set");
is( eval { $gv->NAME }, "__ANON__", "...and an __ANON__ name");
is( eval { $gv->STASH->NAME }, "온ꪵ", "...but leaves stash intact");
%tꖿ:: = ();
$gv = b($sub)->GV;
- isa_ok( $gv, "B::GV", "cleared stash leaves CV with valid GV");
+ object_ok( $gv, "B::GV", "cleared stash leaves CV with valid GV");
is( b($sub)->CvFLAGS & $CVf_ANON, $CVf_ANON, "...and CVf_ANON set");
is( eval { $gv->NAME }, "__ANON__", "...and an __ANON__ name");
is( eval { $gv->STASH->NAME }, "tꖿ", "...but leaves stash intact");
undef %ᖟ레ᅦ::;
$gv = b($sub)->GV;
- isa_ok( $gv, "B::GV", "undefed stash leaves CV with valid GV");
+ object_ok( $gv, "B::GV", "undefed stash leaves CV with valid GV");
is( b($sub)->CvFLAGS & $CVf_ANON, $CVf_ANON, "...and CVf_ANON set");
is( eval { $gv->NAME }, "__ANON__", "...and an __ANON__ name");
is( eval { $gv->STASH->NAME }, "__ANON__", "...and an __ANON__ stash");