naturalist/Perl-BSON — pull request #6 by cub-uanic (2011-12-14 20:49:45+00:00)
Title: Partial fix to workaround 64-bit integers on 32-bit Perl

Everything seems to work fine (via Math::Int64), but tests don't pass, because is_deeply() don't think that original and encoded/decoded hashes are not equal, because each of them uses it's own instances of int64 values.

Here is debug session right when is_deeply entered (non-interested parts were skipped):

.......................................................
989 sub is_deeply {
DB<6> l
990==> my $tb = Test::More->builder;
991
.................
1005: my( $got, $expected, $name ) = @_;
1006
1007: $tb->_unoverload_str( \$expected, \$got );
.................
1019: if( _deep_check( $got, $expected ) ) {
.................

DB<6> x @_
0 HASH(0x993d6f0)
'a' => Math::Int64=SCALAR(0x993d6b0)
-> '1.06099789548264e-314'
'b' => Math::Int64=SCALAR(0x993dac0)
-> 'nan'
'c' => Math::Int64=SCALAR(0x9941740)
-> '-0'
1 HASH(0x90c72a0)
'a' => Math::Int64=SCALAR(0x993dab0)
-> '1.06099789548264e-314'
'b' => Math::Int64=SCALAR(0x993db10)
-> 'nan'
'c' => Math::Int64=SCALAR(0x993d650)
-> '-0'
2 'Int64 decode'
DB<7> n
.......................................................

As you could see, in hashes, passed as first and second argument to is_deeply(), scalar representations of Math::Int64 objects are equal, and so they should be equal when compared. But for some reason, comparsion raise exception after calling _deep_check() in line 1019:

.......................................................
Usage: Math::Int64::_string(self, other, rev) at /home/cub/projects/share/perl/lib/perl5/Test/Builder.pm line 876.
at /home/cub/projects/share/perl/lib/perl5/Test/Builder.pm line 252
Test::Builder::subtest('Test::Builder=HASH(0x91b5780)', 'int64', 'CODE(0x98b7dd8)') called at /home/cub/projects/share/perl/lib/perl5/Test/More.pm line 747
Test::More::subtest('int64', 'CODE(0x98b7dd8)') called at t/10-bson.t line 54
# Child (int64) exited without calling finalize()
not ok 2 - int64
# Failed test 'int64'
# at /home/cub/projects/share/perl/lib/perl5/Test/Builder.pm line 252.
# Looks like you planned 17 tests but ran 2.
# Looks like you failed 1 test of 2 run.
# Looks like your test exited with 9 just after 2.
Debugged program terminated. Use q to quit or R to restart,
.......................................................

According to manual, Test::More::is_deeply() should handle this successfully. Should, but this is not so. May be, this was because _unoverload_str() was called at line 1007. If it's so, then this could be bug in Test::More or in Math::Int64, I don't know.... Unfortunately, I don't have enough time right now to work on this. I hope, my code and investigation could help you solve this problem, or invent some workaround (like don't use Test::More::is_deeply() - may be, solution will be to switch to Test::Differences or Test::Deep).