I am writing a unit test where I have to check whether the key structures of the two hash variables (hashes of hashes) are identical. The key values can differ. The depth of the hashes is arbitary.
The Test::Deep appears to be ideal, but I can't figure out how to make the cmp_deeply ignore the values.
use Test::Deep;
my %hash1 = ( key1 => "foo", key2 => {key21 => "bar", key22 => "yeah"});
my %hash2 = ( key1 => "foo", key2 => {key21 => "bar", key22 => "wow"});
cmp_deeply(\%hash1, \%hash2, "This test should not fail");
outputs:
not ok 1 - This test should not fail
# Failed test 'This test should not fail'
# at demo.pl line 13.
# Compared $data->{"key2"}{"key22"}
# got : 'yeah'
# expect : 'wow'
If a hash would have a known structure I could use a test variable with values ignore(). However, in my case the best solution would be that I wouldn't have to update the structure in the test code.
I tried traversing the %hash1 using Data::Walk and checking that each key exists in %hash2 but found difficult to get the current keys from the $Data::Walk::container value.
Any ideas for a suitable comparison tool?