1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#!/usr/bin/env perl -w
# Test isa_ok() and can_ok() in test.pl
use strict;
use warnings;
BEGIN {
chdir 't' if -d 't';
push @INC, ".";
require 'test.pl';
}
require Test::More;
can_ok('Test::More', qw(require_ok use_ok ok is isnt like skip can_ok
pass fail eq_array eq_hash eq_set));
can_ok(bless({}, "Test::More"), qw(require_ok use_ok ok is isnt like skip
can_ok pass fail eq_array eq_hash eq_set));
isa_ok(bless([], "Foo"), "Foo");
isa_ok([], 'ARRAY');
isa_ok(\42, 'SCALAR');
{
local %Bar::;
local @Foo::ISA = 'Bar';
isa_ok( "Foo", "Bar" );
}
# can_ok() & isa_ok should call can() & isa() on the given object, not
# just class, in case of custom can()
{
local *Foo::can;
local *Foo::isa;
*Foo::can = sub { $_[0]->[0] };
*Foo::isa = sub { $_[0]->[0] };
my $foo = bless([0], 'Foo');
ok( ! $foo->can('bar') );
ok( ! $foo->isa('bar') );
$foo->[0] = 1;
can_ok( $foo, 'blah');
isa_ok( $foo, 'blah');
}
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;
|