Groups | Search | Server Info | Login | Register


Groups > perl.qa > #4

Test2::Tools::Compare is vs. like

Newsgroups perl.qa
Subject Test2::Tools::Compare is vs. like
Message-ID <7B1DD0C4-C4CA-41C5-A78D-79C0B58AE707@petdance.com> (permalink)
Date 2016-07-27 10:03 -0500
From andy@petdance.com (Andy Lester)

Show all headers | View raw


I was going to mail this to Chad directly, but I think it’s worth airing publicly.

As a newcomer to Test2, it was never clear to me until just now when to use is() or like() for deep structures.  Given this code:

    my $errors = do_something();
    is( @{$errors}, 0. ‘No errors back from do_something()’ ); # old way

And the new way to check would be:

    is( $errors, [], ‘No errors back from do_something()’ );

It would be very easy to use this instead:

    like( $errors, [], ‘No errors back from do_something()’ );

And it looks like like() works just fine, but really it will pass even if $errors has something in it.

    is( [], [] ); # Passes
    like( [‘foo’], [] ); # passes but you wouldn’t expect it to.

The docs say "This is the strict checker” and “This is the relaxed checker” for each of them, respectively, but I think it would be worth having something in the docs that explains the differences between the two.

Anyone else have troubles with these two functions?  Or other gotchas where new features aren’t what people switching from Test::More might expect?

Andy

--
Andy Lester => www.petdance.com

Back to perl.qa | Previous | Next | Find similar


Thread

Test2::Tools::Compare is vs. like andy@petdance.com (Andy Lester) - 2016-07-27 10:03 -0500

csiph-web