Re: is(), undef, '' and 0 (was Re: [PATCH lib/DB.pm MANIFEST lib/DB.t] Add Tests for DB.pm)

2001-11-24 Thread chromatic

On Friday 23 November 2001 15:59, you wrote:

 On Fri, Nov 23, 2001 at 03:32:41PM -0700, chromatic wrote:
  +   is( DB::DB(), undef, 'DB::DB() should return undef if $DB::ready is
  false');

 Crap, this doesn't quite work in the general case.

 is( undef, undef ); # ok
 is( 0, undef ); # not ok
 is('', undef ); # ok

 is() uses eq and undef stringifies to ''.  is( $foo, undef ) is a nice
 idiom, though.

I got it from *somewhere*.  I'd almost swear it was in the first version of 
Test::Builder, having been untimely ripped from the womb of pre-wrapper 
Test::More.

 Should is() distinguish between undef, 0 and ''?  Seeing as how it
 already does between undef and 0 (accidentally), I guess it wouldn't
 hurt.

Perl does, why shouldn't the tests?  Something like this only has one problem:

$test = 'undef' unless defined $test;

Most people likely to write tests are smart enough to avoid nasty literal 
phrases like '0 but true' and 'undef'.  I hope.  I left room at lunch to eat 
those words, though.

-- c



is(), undef, '' and 0 (was Re: [PATCH lib/DB.pm MANIFEST lib/DB.t] Add Tests for DB.pm)

2001-11-24 Thread Michael G Schwern

On Fri, Nov 23, 2001 at 03:32:41PM -0700, chromatic wrote:
 + is( DB::DB(), undef, 'DB::DB() should return undef if $DB::ready is false');

Crap, this doesn't quite work in the general case.

is( undef, undef ); # ok
is( 0, undef ); # not ok
is('', undef ); # ok

is() uses eq and undef stringifies to ''.  is( $foo, undef ) is a nice
idiom, though.

Should is() distinguish between undef, 0 and ''?  Seeing as how it
already does between undef and 0 (accidentally), I guess it wouldn't
hurt.

-- 

Michael G. Schwern   [EMAIL PROTECTED]http://www.pobox.com/~schwern/
Perl Quality Assurance  [EMAIL PROTECTED] Kwalitee Is Job One
The truth is you suck!