Date: | Wed, 9 Nov 2005 09:37:05 -0600 (CST) |
From: | Pete Krawczyk <perl [...] bsod.net> |
To: | perl-qa [...] perl.org |
CC: | bug-Test-Simple [...] rt.cpan.org |
Subject: | Test-Simple patch: can_ok() fails if first argument is false |
The following Perl gives Test::More 0.60 and 0.62 heartache:
$ perl -MTest::More=tests,1 -we'can_ok(undef,undef)'
1..1
Use of uninitialized value in concatenation (.) or string at .../5.8.6/Test/More.pm line 501.
Use of uninitialized value in concatenation (.) or string at .../5.8.6/Test/More.pm line 501.
not ok 1 - ->can('')
# Failed test (-e at line 1)
Use of uninitialized value in concatenation (.) or string at .../5.8.6/Test/More.pm line 506.
Use of uninitialized value in concatenation (.) or string at .../5.8.6/Test/More.pm line 506.
# ->can('') failed
# Looks like you failed 1 test of 1.
$
The following patch makes Test::More verify the class isn't false first.
==========================================================================
diff -ur Test-Simple-0.62/lib/Test/More.pm Test-Simple-0.62-patched/lib/Test/More.pm
--- Test-Simple-0.62/lib/Test/More.pm 2005-10-08 01:56:17.000000000 -0500
+++ Test-Simple-0.62-patched/lib/Test/More.pm 2005-11-09 09:22:44.000000000 -0600
@@ -465,6 +465,12 @@
my $class = ref $proto || $proto;
my $tb = Test::More->builder;
+ unless( $class ) {
+ my $ok = $tb->ok( 0, "->can(...)" );
+ $tb->diag(' can_ok() called with empty class or reference');
+ return $ok;
+ }
+
unless( @methods ) {
my $ok = $tb->ok( 0, "$class->can(...)" );
$tb->diag(' can_ok() called with no methods');
==========================================================================
The patch does not address a method name that is undefined.
-Pete K
--
Pete Krawczyk
perl at bsod dot net