AFS
view release on metacpan or search on metacpan
src/inc/Test/More.pm view on Meta::CPAN
sub ok ($;$) {
my($test, $name) = @_;
$Test->ok($test, $name);
}
sub is ($$;$) {
$Test->is_eq(@_);
}
sub isnt ($$;$) {
$Test->isnt_eq(@_);
}
*isn't = \&isnt;
sub like ($$;$) {
$Test->like(@_);
}
sub unlike {
$Test->unlike(@_);
}
sub cmp_ok($$$;$) {
$Test->cmp_ok(@_);
}
sub can_ok ($@) {
my($proto, @methods) = @_;
my $class = ref $proto || $proto;
unless( @methods ) {
my $ok = $Test->ok( 0, "$class->can(...)" );
$Test->diag(' can_ok() called with no methods');
return $ok;
}
my @nok = ();
foreach my $method (@methods) {
local($!, $@); # don't interfere with caller's $@
# eval sometimes resets $!
eval { $proto->can($method) } || push @nok, $method;
}
my $name;
$name = @methods == 1 ? "$class->can('$methods[0]')"
: "$class->can(...)";
my $ok = $Test->ok( !@nok, $name );
$Test->diag(map " $class->can('$_') failed\n", @nok);
return $ok;
}
sub isa_ok ($$;$) {
my($object, $class, $obj_name) = @_;
my $diag;
$obj_name = 'The object' unless defined $obj_name;
my $name = "$obj_name isa $class";
if( !defined $object ) {
$diag = "$obj_name isn't defined";
}
elsif( !ref $object ) {
$diag = "$obj_name isn't a reference";
}
else {
# We can't use UNIVERSAL::isa because we want to honor isa() overrides
local($@, $!); # eval sometimes resets $!
my $rslt = eval { $object->isa($class) };
if( $@ ) {
if( $@ =~ /^Can't call method "isa" on unblessed reference/ ) {
if( !UNIVERSAL::isa($object, $class) ) {
my $ref = ref $object;
$diag = "$obj_name isn't a '$class' it's a '$ref'";
}
} else {
die <<WHOA;
WHOA! I tried to call ->isa on your object and got some weird error.
This should never happen. Please contact the author immediately.
Here's the error.
$@
WHOA
}
}
elsif( !$rslt ) {
my $ref = ref $object;
$diag = "$obj_name isn't a '$class' it's a '$ref'";
}
}
my $ok;
if( $diag ) {
$ok = $Test->ok( 0, $name );
$Test->diag(" $diag\n");
}
else {
$ok = $Test->ok( 1, $name );
}
return $ok;
}
sub pass (;$) {
$Test->ok(1, @_);
( run in 0.605 second using v1.01-cache-2.11-cpan-39bf76dae61 )