diff options
author | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2005-09-06 08:46:37 +0000 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2005-09-06 08:46:37 +0000 |
commit | 35a603864810a769960255e50b84d5fab2473ee8 (patch) | |
tree | f06c95924c1b9485d8fc27409faebe5d5691e00c /t | |
parent | 2c394315b3f8471f6207f6e24e1758be717bbd14 (diff) | |
download | perl-35a603864810a769960255e50b84d5fab2473ee8.tar.gz |
Upgrade to IO 1.22 from gbarr
- Adjust the regression tests to use t/test.pl from bleadperl
when $ENV{PERL_CORE} is defined
- Add can_ok and isa_ok to t/test.pl from the implementation
found in the IO CPAN distribution
p4raw-id: //depot/perl@25355
Diffstat (limited to 't')
-rw-r--r-- | t/test.pl | 62 |
1 files changed, 62 insertions, 0 deletions
@@ -649,4 +649,66 @@ sub fresh_perl_like { $runperl_args, $name); } +sub can_ok ($@) { + my($proto, @methods) = @_; + my $class = ref $proto || $proto; + + unless( @methods ) { + return _ok( 0, _where(), "$class->can(...)" ); + } + + 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(...)"; + + _ok( !@nok, _where(), $name ); +} + +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'"; + } + } + + _ok( !$diag, _where(), $name ); +} + 1; |