X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fsafe_isa.t;h=24af78dad7480eed093ea9973723255ec32a1691;hb=3f26844088a675a3d664adbcd7dffbaf0b2c8c39;hp=5867bc517ffa6084f440d1b11d3151a2b7c8fb6d;hpb=a8b752e9c3003190e519e2e81bafdd6fe37fa7dc;p=p5sagit%2FSafe-Isa.git diff --git a/t/safe_isa.t b/t/safe_isa.t index 5867bc5..24af78d 100644 --- a/t/safe_isa.t +++ b/t/safe_isa.t @@ -1,34 +1,43 @@ use strict; -use warnings FATAL => 'all'; -use Test::More qw(no_plan); +use warnings; +use Test::More tests => 28; { package Foo; sub new { bless({}, $_[0]) } } -{ package Bar; our @ISA = qw(Foo); sub bar { 1 } } +{ package Bar; our @ISA = qw(Foo); sub bar { $_[1] } } my $foo = Foo->new; my $bar = Bar->new; my $blam = [ 42 ]; +my $undef; # basic isa usage - ok($foo->isa('Foo'), 'foo isa Foo'); ok($bar->isa('Foo'), 'bar isa Foo'); ok(!eval { $blam->isa('Foo'); 1 }, 'blam goes blam'); +ok(!eval { $undef->isa('Foo'); 1 }, 'undef goes poof'); + ok(!$foo->can('bar'), 'foo !can bar'); ok($bar->can('bar'), 'bar can bar'); ok(!eval { $blam->can('bar'); 1 }, 'blam goes blam'); +ok(!eval { $undef->can('bar'); 1 }, 'undef goes poof'); use Safe::Isa; ok($foo->$_isa('Foo'), 'foo $_isa Foo'); ok($bar->$_isa('Foo'), 'bar $_isa Foo'); -ok(eval { $blam->$_isa('Foo'); 1 }, 'no boom today'); +ok(eval { is($blam->$_isa('Foo'), undef, 'blam isn\'t Foo'); 1 }, 'no boom today'); +ok(eval { is($undef->$_isa('Foo'), undef, 'undef isn\'t Foo either'); 1 }, 'and no boom tomorrow either'); ok(!$foo->$_can('bar'), 'foo !$_can bar'); ok($bar->$_can('bar'), 'bar $_can bar'); -ok(eval { $blam->$_can('bar'); 1 }, 'no boom today'); +ok(eval { is($blam->$_can('bar'), undef, 'blam can\'t bar'); 1 }, 'no boom today'); +ok(eval { is($undef->$_can('bar'), undef, 'undef can\'t bar either'); 1 }, 'and no boom tomorrow either'); ok($foo->$_call_if_object(isa => 'Foo'), 'foo $_call_if_object(isa => Foo)'); ok($bar->$_call_if_object(isa => 'Foo'), 'bar $_call_if_object(isa => Foo)'); -ok(eval { $blam->$_call_if_object(isa => 'Foo'); 1 }, 'no boom today'); +is($bar->$_call_if_object(bar => ), undef, 'bar $_call_if_object(bar => undef)'); +is($bar->$_call_if_object(bar => 2), 2, 'bar $_call_if_object(bar => 2)'); +ok(eval { is($blam->$_call_if_object(isa => 'Foo'), undef, 'blam can\'t call anything'); 1 }, 'no boom today'); +ok(eval { is($undef->$_call_if_object(isa => 'Foo'), undef, 'undef can\'t call anything'); 1 }, 'and no boom tomorrow either');