develooper Front page | perl.qa | Postings from June 2016

Re: Writing our own modules in Test2

Thread Previous | Thread Next
From:
Andy Lester
Date:
June 27, 2016 14:35
Subject:
Re: Writing our own modules in Test2
Message ID:
49AF4CF5-4B2D-4A99-90E5-C9C6AA4EAE06@petdance.com

> On Jun 24, 2016, at 4:41 PM, Buddy Burden <barefootcoder@gmail.com> wrote:
> 
>    is_true($val);
>    is_false($val);
> 
> Because with just `ok($val)` you can tell whether it's true or false, but, when it inevitably fails, you really want to know what the bad value turned out to be.


I have a bool_eq() so you can do this:

bool_eq( $want_foos, scalar @foos );

without having to do

if ( $want_foos ) {
    ok( scalar @foos );
}
else {
    is( scalar @foos, 0 );
}

We were also writing that as

is( !!$want_foos, !!(scalar @foos) );

which works, but obscures the meaning.

I don’t like the name bool_eq() (“booleans are equal”) but it was the best I could come up with.

--
Andy Lester => www.petdance.com


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About