Yves wrote:
> Ok, ive started work on this, however there is a minor problem: The
> test in circular_refs regarding rt.cpan.org 11623. (I added names to
> make it easier to work with.)
> 
> {
>     # rt.cpan.org 11623
>     # Make sure the circular ref checks don't get confused by a reference 
>     # which is simply repeating.
>     my $a = {};
>     my $b = {};
>     my $c = {};
> 
>     is_deeply( [$a, $a], [$b, $c], "rt.cpan.org 11623 - 1" );
>     is_deeply( { foo => $a, bar => $a }, { foo => $b, bar => $c },
>                "rt.cpan.org 11623 - 2" );
>     is_deeply( [\$a, \$a], [\$b, \$c],"rt.cpan.org 11623 - 3" );
> }
> 
> In order to make a real structural comparison these tests have to go. 
> In order to determine structural equivelence you have to include a
> methodology of adding or altering data. If by doing so the two
> structures changes differently then you have different structures, if
> the structures are still equivelent afterwards you have equivelent
> structures. This example would clearly fail the test.

After talking with Ovid some in the kitchen I'm of the opinion that
is_deeply() is currently doing the right thing and that these tests cannot
go.  Largely it comes down to the Principle of Least Surprise.  

Here's an example.  A user wants to test the results of some function that,
in this situation, includes some duplicated data.  So they might construct 
their "expected" structure like so to save a little time:

my %thing = { foo => 42, bar => 23 };

my %expect = ( stuff => 23,
               wiff  => \%thing,
               wham  => \%thing
             );

Internally the code might not reuse the same reference.  The user would be
very surprised if the comparison failed.  In fact, I would even argue that
this violates some of the black boxness of the test.  In much the same way
that we don't check to see if a given piece of data is blessed, tied or
overloaded, we wouldn't care if we have a repeating reference or two 
different references to equivalent data.

Furthermore, the current behavior provides the more flexible option.  If
a user doesn't care about the particulars of the references in their
structure, is_deeply() works.  If they *do* then the user can always run
an addition test.  But if we made is_deeply() repeating reference aware then
the user who does not care about that cannot use is_deeply() at all.

So, I conclude that is_deeply()'s behavior is ok and something like Test::Deep
should be enhanced with an option to deal with this problem.


-- 
Michael G Schwern     [EMAIL PROTECTED]     http://www.pobox.com/~schwern
Just call me 'Moron Sugar'.
        http://www.somethingpositive.net/sp05182002.shtml

Reply via email to