read this one first, it may resolve everything - was Re: [code-review] Please review String::FlexMatch
Fergal Daly <[email protected]> Mon, 8 Sep 2003 18:02:54 +0100
| Newsgroups | gmane.comp.lang.perl.code-review-ladder |
|---|---|
| Message-ID | <[email protected]> |
While replying below I had a "aha" moment which may get to the root of our
argument.
It struck me that you may be getting the impression that is_deeply() only
recurses 1 level down. This is a very valid interpretation of the docs
however it is not the case. is_deeply() goes deep deep deep and in fact with
a recent patch it handles circular data structures too.
I think you're idea of is_deeply is something like
sub is_deeply
{
my ($got, $exp) = @_;
if (ref($exp) eq "ARRAY")
{
for (my $i=0; $i<@$exp; $i++)
{
is($got[$i], $exp[$i]);
}
}
elsif(ref($exp) eq "HASH")
{
...
}
else
{
is($this, $that);
}
}
and that's kind of what the docs say it is but it totally isn't.
So is that it or is it "on with round n"?
On Monday 08 September 2003 10:53, Tony Bowden wrote:
> Yes, but the point remains that they should both call the same
> comparison code. I don't care where it is, but they should both follow
> the same path, not add their own.
That would require changing Test::More and Test::Builder in order to save 3
lines of code. It would also complicate the production of diagnostic output
enough to nullify that saving.
I think our real difference is that you see strong relation between is() and
is_deeply(), I don't. They don't claim to be the same, they do claim to be
"similar" but that is ambiguous. is() to be an abbreviation of is_eq whereas
is_deeply() is a completely different kettle of fish.
> I'd see the structure as being something like:
>
> sub is { do_compare($X, $Y) and report )
>
> sub is_deeply {
> while ($X = $struct1->next, $Y = $struct2->next) {
> do_compare($X, $Y) and gather reports
> }
> report based on gathered reports
> }
>
> No comparison behaviour whatsoever should live in is_deeply.
That's very close to what Test::Deep does however it is somewhat far from what
Test::More does. It also turns is() into a deep test because do_compare has
to be able to descend as far as necessary.
AHA moment...
F