http://qs1969.pair.com?node_id=471772


in reply to Do you consider these different or the same?

You are asking the wrong questions. Instead, ask –
  1. What is the purpose of Test::More::is_deeply?
  2. What, then, should its semantics be?

My answer to the first is that is_deeply's purpose is to make it easy to test complex observed values by comparing them with given expected values.

My answer to the second, then, is that is_deeply should consider the observed and expected values to be equivalent if both have the same structure and subvalues, ignoring sharing. (Remember, I am talking semantics here, not implementation.)

Why ignore sharing? Because it rarely matters in tests. By ignoring it we make the common case easier for testers, who frequently hand-roll expected values. This goes back to the purpose of is_deeply; convenience matters.

As to your questions, then, here is how I answer. In the first case, $ar1 and $ar2 are equivalent. Both have the same structure and subvalues – [{},{}]. In the second case, they are not equivalent; [{a=>'foo'},{a=>'foo'}] differs from [{a=>'foo'},{}].

Cheers,
Tom

  • Comment on Re: Do you consider these different or the same?

Replies are listed 'Best First'.
Re^2: Do you consider these different or the same? (eq)
by tye (Sage) on Jul 02, 2005 at 02:44 UTC

    Exactly.

    Also note that the name "is_deeply" comes from the is() function that only cares about eq. So "is_deeply" is meant to convey applying eq deeply between two structures. Something that does more than that needs a different name if it is part of Test::More.

    The "deeply" part means that $a vs. "$a" fail the test if $a is a reference because only leaves are compared.

    - tye