Subject: | eq_deeply() is not quite ready for general use - diagnostics on exceptions |
I was wanting a simple procedure for comparing two data values/structures for 'equality'. The documentation for Test::Deep::eq_deeply looked like this routine would be perfect, as the docs said the routine could be used outside of a testing environment:
This is the same as cmp_deeply() it just returns true or false,
however it never outputs any diagnostics or talks to Test::Builder,
so you can use it in a normal program, rather than in a test script.
Unfortunately as I tested I found that there were side-effects from merely 'use'ing it. This is a simple example of the problem:
perl -M"Test::Deep" -e "die 'boo!'"
boo! at -e line 1.
# Looks like your test died before it could output anything.
That is, after 'use'ing Test::Deep any fatal (?) exceptions will cause the test environment diagnostic to appear. I imagine that 'use'ing Test::Builder is causing the side-effect.
If this side-effect can't be easily fixed, could you add a caveat to the docs mentioning this (perhaps inconsequential to some) diagnostic gotcha?
As well, if you have suggestions for equivalent functionality from other modules, that would be appreciated. Currently I'm reduced to using this:
sub eq_deeply_alt {
my ( $r1, $r2 ) = @_;
my $s1 = Data::Dumper->new([$r1])->Indent(0)->Terse(1)->Sortkeys(1)->Dump();
my $s2 = Data::Dumper->new([$r2])->Indent(0)->Terse(1)->Sortkeys(1)->Dump();
return $s1 eq $s2;
}