Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Test2::Tools::Compare is vs. like

2 views
Skip to first unread message

Andy Lester

unread,
Jul 27, 2016, 11:15:02 AM7/27/16
to Perl QA
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

0 new messages