Final reply to myself :-). Attached is a patch that fixes this test case without breaking any others so I think it's OK. It basically centralises the circular ref checking into _deep_check and then reroutes eq_array and eq_hash into that. This ensures that all types of refs are checked for cirularitinessness.
Fergal On Sun, Jan 23, 2005 at 08:04:23PM +0000, Fergal Daly wrote: > Oops, actually the latest is_deeply doesn't correctly handle _all_ circular > structures. If the circle includes a hash or an array it will work but if it > only includes scalar references then it will recurse indefinitely. I've > filed a bug report on rt. Test case below > > use strict; > use warnings; > > use Test::More 'no_plan'; > > my ($r, $s); > > $r = \$r; > $s = \$s; > > is_deeply($s, $r); > > Fergal > > On Sun, Jan 23, 2005 at 07:13:13PM +0000, Fergal Daly wrote: > > What version of Test::More? Only the most recent versions can handle > > circular data structures, so I'd guess you have a circular data structure > > and an older version, > > > > Fergal
--- ./t/circular_data.t.orig 2005-01-23 20:10:00.085678928 +0000 +++ ./t/circular_data.t 2005-01-23 20:12:29.096025912 +0000 @@ -13,7 +13,7 @@ } use strict; -use Test::More tests => 5; +use Test::More tests => 6; my $a1 = [ 1, 2, 3 ]; push @$a1, $a1; @@ -31,3 +31,10 @@ is_deeply $h1, $h2; ok( eq_hash ($h1, $h2) ); + +my ($r, $s); + +$r = \$r; +$s = \$s; + +ok( eq_array ([$s], [$r]) ); --- ./lib/Test/More.pm.orig 2005-01-23 20:09:45.425907552 +0000 +++ ./lib/Test/More.pm 2005-01-23 20:18:05.675858000 +0000 @@ -1112,7 +1112,7 @@ sub eq_array { local @Data_Stack; local %Refs_Seen; - _eq_array(@_); + _deep_check(@_); } sub _eq_array { @@ -1125,13 +1125,6 @@ return 1 if $a1 eq $a2; - if($Refs_Seen{$a1}) { - return $Refs_Seen{$a1} eq $a2; - } - else { - $Refs_Seen{$a1} = "$a2"; - } - my $ok = 1; my $max = $#$a1 > $#$a2 ? $#$a1 : $#$a2; for (0..$max) { @@ -1171,6 +1164,13 @@ $ok = 1; } else { + if( $Refs_Seen{$e1} ) { + return $Refs_Seen{$e1} eq $e2; + } + else { + $Refs_Seen{$e1} = "$e2"; + } + my $type = _type($e1); $type = '' unless _type($e2) eq $type; @@ -1213,7 +1213,7 @@ sub eq_hash { local @Data_Stack; local %Refs_Seen; - return _eq_hash(@_); + return _deep_check(@_); } sub _eq_hash { @@ -1226,13 +1226,6 @@ return 1 if $a1 eq $a2; - if( $Refs_Seen{$a1} ) { - return $Refs_Seen{$a1} eq $a2; - } - else { - $Refs_Seen{$a1} = "$a2"; - } - my $ok = 1; my $bigger = keys %$a1 > keys %$a2 ? $a1 : $a2; foreach my $k (keys %$bigger) {