Ovid wrote:
There's a nasty bug in the latest development version of Test::Differences. By
applying a patch which allows this to pass (it currently won't):
eq_or_diff { foo => 1 }, { foo => '1' };
It also allows this to pass:
eq_or_diff [ { foo => 1 } ], { foo => '1' };
Ow, ow, ow. This is terrible. Fortunately, that's what development versions
are for.
I'm thinking about rewriting Test::Differences to use &Test::More::is_deeply
for the test and only diff if there are differences. Currently it uses
Data::Dumper or its own internal flattening and and compares the string outputs.
I'd recommend using Test::Deep if you can take the dependency hit.
There are two side-effects I can think of. First, the string/numeric value
comparison will work correctly. Second, the 'Array of HashRef' diff output will
change dramatically. There's an internal hack which assumes and an AoH is a
table (likely pulled from DBI, I assume), and this:
eq_or_diff [ { name => 'Bob', id => 1 } ],
[ { name => 'Bob', id => 2 } ], 'aoh';
Generates this:
# Failed test 'aoh'
# at eq_or_diff.t line 13.
# +----+---------+----------+
# | Elt|Got |Expected |
# +----+---------+----------+
# | 0|id,name |id,name |
# * 1|1,Bob |2,Bob *
# +----+---------+----------+
I find this mcch harder to read, but others may appreciate the hash keys being
pulled out as headers.
Maybe line them up and space them out?
# +----+----------+----------+
# | Elt|Got |Expected |
# +----+----------+----------+
# | 0|id, name |id, name |
# * 1|1, Bob |2, Bob *
# +----+----------+----------+
I dunno if wedging an array-of-hashes into a table is such a hot idea. It
looks completely different from any other Perlish way hashes are represented.
It's not obvious that "Elt" 0 is the keys and "Elt" 1 is the values. If you
must force everything to use the same format, maybe spell it out?
# +--------+---------+----------+
# | |Got |Expected |
# +--------+---------+----------+
# | keys |id, name |id, name |
# * values |1, Bob |2, Bob *
# +--------+---------+----------+
Does anyone object to me breaking this? Are there any problems that I haven't
thought of? (There usually are)
I think expecting 1 to equal "1" complies with DWIM. It might generate some
fixage [1], but is worth it. Completely switching out the comparison backend
will probably lead to other differences, like the blessed vs goyum reference
equality change.
[1] http://www.nntp.perl.org/group/perl.qa/2008/03/msg10460.html
--
Just call me 'Moron Sugar'.
http://www.somethingpositive.net/sp05182002.shtml