On Mon, Jun 27, 2016 at 4:34 PM, Andy Lester <a...@petdance.com> wrote:

>
> On Jun 24, 2016, at 4:41 PM, Buddy Burden <barefootco...@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
>
>

Reply via email to