Subject: | Comparing an array of hashes with non-scalar values is broken |
The following test-case is broken:
use strict;
use warnings;
use Test::More 'no_plan';
use Test::Differences;
my $VAR1 = [
{
a => 1
},
{
b => 1,
c => [ ],
}
];
my $VAR2 = [
{
a => 1
},
{
b => 1,
c => [ ],
}
];
eq_or_diff $VAR1, $VAR2;
# Failed test at t/t.t line 26.
# +----+----------------------------+----------------------------+
# | Elt|Got |Expected |
# +----+----------------------------+----------------------------+
# | 0|a,b,c |a,b,c |
# | 1|1,<undef>,<undef> |1,<undef>,<undef> |
# * 2|<undef>,1,ARRAY(0x854fb44) |<undef>,1,ARRAY(0x86a5fd8) *
# +----+----------------------------+----------------------------+
# Looks like you failed 1 test of 1.
So, for some reason it is stringifying the anonymous arrayrefs.
This is because there is a typo in the following function which tries to
detect if in an array of hashes, the hash is flat (ie it is probably a
'table' format), or if it's a more complicated data structure:
sub _isnt_HASH_of_scalars {
return 1 if ref ne "HASH";
return scalar grep ref, keys %$_;
}
Obviously all the keys in the hash are going to be scalars - it should
check the values of the hash. Therefore, the line should read:
return scalar grep ref, values %$_;