Nicholas Clark wrote:
> On Sat, Feb 14, 2009 at 12:57:45PM +0200, Gabor Szabo wrote:
>> On Thu, Feb 12, 2009 at 3:18 PM, Nicholas Clark <n...@ccl4.org> wrote:
>>> I find
>>>
>>>    isnt($foo, undef);
>>>
>>> useful as it gives better failure diagnostics than
>>>
>>>    ok(defined $foo);
>>>
>> Wouldn't it be better to write this
>>
>>      is_defined($foo);
>>
>> Which, on failure would print
>> #          got: undef
>> #     expected: anything else
>>
>> as it does your example.
>>
>> Schwern, can this be added to Test::More ?
> 
> Assuming that isnt() isn't going to be removed from Test::More, I don't see
> this as a good idea. Your proposed is_defined($foo) is the same amount of
> typing as isnt($foo, undef), gives no better diagnostics, is no clearer in
> its intent than isnt($foo, undef), and increases the complexity of the
> interface to Test::More by 1 function. It feels like:
> 
>     Although the Perl Slogan is There's More Than One Way to Do It, I
>     hesitate to make 10 ways to do something.  :-)
> 
>     http://groups.google.com/group/comp.lang.perl/msg/b7b1650e90b89c0b

Pretty much my feeling.

isnt($foo, undef); is doing exactly its job.  It's flexible, gives good
diagnostics and reads much like English.  Also it means we don't have to have
a smattering of is_blank(), is_not_blank(), is_empty_string(), is_zero(),
is_not_zero(), etc...

If you prefer that sort of thing, knock yourself out.

    package My::Test;
    use base "Test::Builder::Module";
    our @EXPORT = qw(is_defined);

    sub is_defined {
        my($thing, name) = @_;

        my $tb = __PACKAGE__->builder;
        return $tb->isnt_eq($thing, undef, $name);
    }


-- 
3. Not allowed to threaten anyone with black magic.
    -- The 213 Things Skippy Is No Longer Allowed To Do In The U.S. Army
           http://skippyslist.com/list/

Reply via email to