develooper Front page | perl.module-authors | Postings from January 2010

Re: Comparing hashes

Bruce Gray
January 17, 2010 20:09
Re: Comparing hashes
Message ID:

On Jan 17, 2010, at 6:31 PM, Geoffrey Leach wrote:

> I'm dealing with an error report from cpantesters for Getopt::Auto.
> The problem arrises out of using Test::More::is_deeply to compare a
> hash with what's generated at run time: it comes out different.
> I've delt with this problem in my own testing, and have spent some  
> time
> getting it 'just right'. I suspect the problem arrises out of how Perl
> organizes the hash. The version with the problem is perl-5.6.2. Later
> versions pass. Given that I'm using an unsupported feature, things may
> well come unglued in the future.
> So, are there any suggestions? Test::Deep? 'use Perl 5.8.0'?
> Thanks.

On Darwin 10.5, I have duplicated the problem with a custom-compiled  
Perl 5.6.2.
The problem is caused by Getopt::Auto's use of each() to build @spec  
in sub _parse_pod.

Since the iteration order of each() is not guaranteed between versions  
of Perl
(and sometimes even between program runs; see `perldoc -f each`),
you will either need to
1) pre-sort both the inputs to is_deeply, or
2) just apply the attached patch.

The patch has been tested against 5.6.2 and 5.10. It changes sub  
to build @spec from within a for loop of sorted keys, and changes the  
of the expected arrays in 03-options_bare.t and 03-options_text.t .

Hope this helps,
Bruce Gray (Util of PerlMonks)
Posting from the excellent Perl Oasis conference Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About