develooper Front page | | Postings from July 2016

Test2::Tools::Compare is vs. like

Thread Next
Andy Lester
July 27, 2016 15:04
Test2::Tools::Compare is vs. like
Message ID:
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 Lester =>

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About