On Tuesday 09 September 2003 15:29, Tony Bowden wrote: > On Tue, Sep 09, 2003 at 01:25:22PM +0100, Adrian Howard wrote: > > >1) ok $str1 eq $str2; > > >2) is $str1, $str2; > > >3) is_deeply [$str1], [$str2]; > > >4) is_deeply $str1, $str2; > > All should pass as far as I am concerned.
I agree. There is no difference between them except the class into which they are blessed and is_deeply is supposed to ignore classes. > my $str1 = MyString->new("foo", "bar"); > my $str2 = MyOtherString->new("foo", "baz"); Now they _do_ differ by more than just class and it should be a fail, although I must admit that even with the current is_deeply it will be a pass. I consider that a bug and it's something I avoided in Test::Deep by using Scalar::Util::refaddr, I just never backported that to Test::More. The reason I want it to fail is because if I pass these objects (and they are definitely objects, they're only strings if you squint) into some other function which calls a method on them then "bar" vs "baz" might be a very crucial difference. Or if I pass them to a function that behaves differently for strings and objects, I'll get the object behaviour, not the string behaviour. For me, it comes down to 2 things, utility and the total pain in the backside that it would be to even get close to implementing what's being asked for. <utility> Which is more useful? Scenario A: "Mr deeply please check that datastructure and tell me if it's an array of a type 5 widgets" "I checked and it's exactly what you asked for no way could it be anything different" Scenario B: "Mr deeply please check that datastructure and tell me if it's an array of a type 5 widgets" "Well, some of them definitely were and some of them had labels on them that said they were so I didn't bother checking those" "which ones has labels?" "none of them, all of them, some of them, I can't remember. Relax it's only testing. Look at them yourself if you want to be sure" </utility> Here's my pop quiz what is the result of this package Counter; use overload '""' => \&get; sub new { my $val = 1; return bless \$val, shift; } sub get { my $self = shift; return ${$self}++; } my $counter = Couner->new; is_deeply( { a => $counter, b => $counter}, { a => 1, $b => 2} ); for bonus points, what will be the puzzling diagnostic message? <pain> We need changes in _deep_check, in diagnostics, we also need to forget about handling circular structures and we need to document it properly so that this doesn't happen again. </pain> Another quiz, given that is_deeply is supposed to ignore blessings on references, see http://www.mail-archive.com/[EMAIL PROTECTED]/msg01679.html how about this sub three_tests { my ($a, $b) = @_; is_deeply($a, $b); bless $a, "wibble"; is_deeply($a, $b); bless $a, "MyString"; is_deeply($a, $b); } three_tests({value => "cat"}, {value => "cat"}); three_tests({value => "cat"}, "cat"); Finally did anyone's intuitive knowledge of is_deeply include this possibility? is_deeply($a, $b) OK is_deeply($b, $c) OK is_deeply($a, $c) NOT OK or this my $a = bless [$something], "APackage"; my $b = fn(); if (is_deeply($a, $b)) { isa_ok($b->[0], "anotherPackage"); } Not an ARRAY reference at line 5. The outcome of a good test should indicate 1 thing and 1 thing only. It should not mean A was true or B was true because then you have to test specifically for A or for B in which case why bother with the original test, F