Test2::Tools::Compare is vs. like

[email protected] (Andy Lester) Wed, 27 Jul 2016 10:03:53 -0500
Newsgroups perl.qa
Message-ID <[email protected]>
I was going to mail this to Chad directly, but I think it=E2=80=99s =
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 =3D do_something();
    is( @{$errors}, 0. =E2=80=98No errors back from do_something()=E2=80=99=
 ); # old way

And the new way to check would be:

    is( $errors, [], =E2=80=98No errors back from do_something()=E2=80=99 =
);

It would be very easy to use this instead:

    like( $errors, [], =E2=80=98No errors back from do_something()=E2=80=99=
 );

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

    is( [], [] ); # Passes
    like( [=E2=80=98foo=E2=80=99], [] ); # passes but you wouldn=E2=80=99t=
 expect it to.

The docs say "This is the strict checker=E2=80=9D and =E2=80=9CThis is =
the relaxed checker=E2=80=9D 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=E2=80=99t what people switching from Test::More =
might expect?

Andy

--
Andy Lester =3D> www.petdance.com