-----BEGIN PGP SIGNED MESSAGE----- Moin,
On 23-Nov-01 Nicholas Clark tried to scribble about: > On Fri, Nov 23, 2001 at 05:59:56PM -0500, Michael G Schwern 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. >> >> Should is() distinguish between undef, 0 and ''? Seeing as how it >> already does between undef and 0 (accidentally), I guess it wouldn't >> hurt. > > I really think it should distinguish between undef and ''. > Test::ok makes the distinction, and I find that useful. > (and a reason to use Test; rather than use Test::More > [if that's not a red rag to a Schwern, what is? :-) ]) > > In the general case I want to test that $foo is an empty defined string, > where undef will be an error (probably an error not forseen when I was > writing the test case). Or the reverse: If I want totest whether $foo is undef, '' should be a failed test. use Math::String; use test::More; $x = Math::String->new('ABC'); # NaN => undef on stringify is ($x, undef); # ok $x = Math::String->new(''); # '' => '' on stringify is ($x, undef); # doesn't fail as it should > If I mean '' and undef to be equivalently correct, I usually want to > express that explicitly. Like: is ($x || '', ''); Cheers, Tels - -- perl -MDev::Bollocks -e'print Dev::Bollocks->rand(),"\n"' quickly enable 24/365 communities http://bloodgate.com/perl My current Perl projects PGP key available on http://bloodgate.com/tels.asc or via email -----BEGIN PGP SIGNATURE----- Version: 2.6.3i Charset: latin1 iQEVAwUBO/7yUXcLPEOTuEwVAQFaKgf+P5Jsllg+3Lm8ltvoiBEtVcmIRMRlqf9j 7I6kLSWJj2GCAgge6/o9/pCfumrVNeRmkRiG8prjxVelKGd55AeYgwTcfQv2vDcm SBVcQc9VfCuIj5T/2mQtxzeGwoxScLIW/pH5G2D3/+MuWBiyuRWQ1rxsnaoRQJrz Zi6nchW45c2HxMMGqhSaBFMRAsp3gLmlfotG6EKih9BRxzZVLXenaC+b2NeNKIBJ 3a15h7t9HVcYGKFMQwsyA+HlsAzXEezzMQB1GYWa+D0DoMKCCaVwGehFjxHdqjpX CbdySPtuex7Xn3kTAF4LjNpX5f3GSWbl8GpMHUNWFXaCdiwwyIk/BA== =qtXV -----END PGP SIGNATURE-----