From: Karen Etheridge Date: Wed, 1 Oct 2014 04:12:52 +0000 (-0700) Subject: add some test cases to show that undef invocants are handled too X-Git-Tag: v1.000006~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=16ec030436aae519028f084ba3ed42adc82e78b1;p=p5sagit%2FSafe-Isa.git add some test cases to show that undef invocants are handled too --- diff --git a/t/safe_isa.t b/t/safe_isa.t index f9721e1..837f3c4 100644 --- a/t/safe_isa.t +++ b/t/safe_isa.t @@ -1,6 +1,6 @@ use strict; use warnings FATAL => 'all'; -use Test::More tests => 15; +use Test::More tests => 20; { package Foo; sub new { bless({}, $_[0]) } } { package Bar; our @ISA = qw(Foo); sub bar { 1 } } @@ -8,27 +8,34 @@ use Test::More tests => 15; 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 { $undef->$_isa('Foo'); 1 }, 'nor 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 { $undef->$_can('bar'); 1 }, 'nor 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'); +ok(eval { $undef->$_call_if_object(isa => 'Foo'); 1 }, 'nor tomorrow either');