Re: is(), undef, '' and 0 (was Re: [PATCH lib/DB.pm MANIFEST lib/DB.t] Add Tests for DB.pm)
On Sat, Nov 24, 2001 at 02:56:54PM -0700, chromatic wrote: > > 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. I was using it without realizing it subtly didn't work. > > 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? Ok, just uploaded Test::Simple 0.34 to CPAN which makes undef a beast different from 0 or ''. Let's see how it goes over. http://www.pobox.com/~schwern/src/Test-Simple-0.34.tar.gz -- Michael G. Schwern <[EMAIL PROTECTED]>http://www.pobox.com/~schwern/ Perl Quality Assurance <[EMAIL PROTECTED]> Kwalitee Is Job One local $variable for local @people;
is(), undef, '' and 0 (was Re: [PATCH lib/DB.pm MANIFEST lib/DB.t] Add Tests for DB.pm)
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!
Re: is(), undef, '' and 0 (was Re: [PATCH lib/DB.pm MANIFEST lib/DB.t] Add Tests for DB.pm)
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