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

Re: Writing our own modules in Test2

Thread Previous | Thread Next
From:
Lasse Makholm
Date:
June 30, 2016 08:57
Subject:
Re: Writing our own modules in Test2
Message ID:
CAGDbts=M5vWJ8yi68JAkWHbWfhMVXr9Lw6+_FH5Bin7oTaNH7g@mail.gmail.com
On Mon, Jun 27, 2016 at 4:34 PM, Andy Lester <andy@petdance.com> wrote:

>
> 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.
>

bool_not_xor_ok() ? :-D

Kidding aside, I would argue that using a conditional is actually the more
readable option in this particular case, though I'd probably compress it
down to:

$want_foos
    ? ok(scalar @foos, 'got some foos')
    :  is(scalar @foos, 0, 'got no foos');

I find that minimizing the logic inside the argument list makes my tests
more readable...

That doesn't negate the need for a bool_eq() though...

How about is_truth($got_bool, $expected_bool) ?

That seems to line up nicely with is_true() and is_false()...

/L


>
> --
> 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