[Pdx-pm] is_deeply and objects

Michael G Schwern schwern at pobox.com
Fri Feb 25 15:06:18 PST 2005


On Fri, Feb 25, 2005 at 02:40:01PM -0800, Josh Heumann wrote:
> Test::More::is_deeply doesn't seem to differentiate between hashes and
> blessed hashes.  Anyone know why?

Because then it would be harder to do this:

  is_deeply( $some_object, { foo => 42, bar => 23 } );

Also, what about this?

  package Foo;
  sub new { return bless { foo => 42 } }

  package Bar;
  @ISA = qw(Foo);

  package main;
  use Test::More tests => 1;

  my $foo = Foo->new;
  my $bar = Bar->new;

  is_deeply( $foo, $bar );

If is_deeply were object-aware should that pass or fail?  Maybe, maybe not.

So I decided to simply ignore the whole problem.  For similar reasons
is_deeply() honors overloading.  If you hand it a string overloaded object
it'll compare it as that string.

In the end, is_deeply() can have only one behavior and is one-size-fits-most.
For more flexibility use Test::Deep.


> This question is posed in honor of Schwern's arrival.  Schwern: who loves
> ya, baby?

According to my spam folder, Jeanna11111 is hot and waiting for me right now.



More information about the Pdx-pm-list mailing list