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

Test2::Tools::Compare is vs. like

Thread Next
From:
Andy Lester
Date:
July 27, 2016 15:04
Subject:
Test2::Tools::Compare is vs. like
Message ID:
7B1DD0C4-C4CA-41C5-A78D-79C0B58AE707@petdance.com
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


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