On Thursday 27 February 2003 16:40, [EMAIL PROTECTED] wrote:
> > is_deeply() ignores the classes of blessed refs. So
> >
> > perl -MTest::More=no_plan -e 'is_deeply(bless([], "a"), bless([], "b"))'
> >
> > passes,
>
> Oh.  Not sure if that's a bug or a feature.  Discuss it on perl-qa.

I think that although a test that ignores blessed classes could be handy in 
some circumstances (ie programming in general), I reckon in the context of 
test suites it's a bug.

If fixing it makes some tests fail then it means either the tests weren't 
really correct or a genuine bug has been discovered.

While I'm at it, a definite problem is that a ref and the stringified version 
of the ref are currently considered equal, so

perl -MTest::More=no_plan -e '$a=[];is_deeply($a, $a."", "should fail")'

passes.

The first patch below fixes the second problem. The second patch fixes the 
first problem (if you think it is a problem) and will only apply cleanly 
after patch1,

F

-- 
Do you need someone with lots of Unix sysadmin and/or lots of OO software 
development experience? Go on, giz a job.
My CV - http://www.fergaldaly.com/cv.html

--- ./lib/Test/More.pm.orig     2002-08-26 17:20:41.000000000 +0100
+++ ./lib/Test/More.pm  2003-02-21 03:37:56.000000000 +0000
@@ -937,7 +937,7 @@
     my($this, $that, $name) = @_;
 
     my $ok;
-    if( !ref $this || !ref $that ) {
+    if( !ref $this && !ref $that ) {
         $ok = $Test->is_eq($this, $that, $name);
     }
     else {
@@ -984,8 +984,9 @@
     foreach my $idx (0..$#vals) {
         my $val = $vals[$idx];
         $vals[$idx] = !defined $val ? 'undef' : 
-                      $val eq $DNE  ? "Does not exist"
-                                    : "'$val'";
+                      ref $val ? $val eq $DNE  ? "Does not exist"
+                                               : $val
+                               : "'$val'"
     }
 
     $out .= "$vars[0] = $vals[0]\n";
@@ -1008,7 +1009,7 @@
 #'#
 sub eq_array  {
     my($a1, $a2) = @_;
-    return 1 if $a1 eq $a2;
+    return 1 if !ref $a1 and ! ref $a2 and $a1 eq $a2;
 
     my $ok = 1;
     my $max = $#$a1 > $#$a2 ? $#$a1 : $#$a2;
@@ -1034,7 +1035,7 @@
         # Quiet uninitialized value warnings when comparing undefs.
         local $^W = 0; 
 
-        if( $e1 eq $e2 ) {
+        if( ! ref $e1 and ! ref $e2 and $e1 eq $e2 ) {
             $ok = 1;
         }
         else {
@@ -1083,7 +1084,7 @@
 
 sub eq_hash {
     my($a1, $a2) = @_;
-    return 1 if $a1 eq $a2;
+    return 1 if !ref $a1 and ! ref $a2 and $a1 eq $a2;
 
     my $ok = 1;
     my $bigger = keys %$a1 > keys %$a2 ? $a1 : $a2;



--- lib/Test/More.pm.fixed_ref  2003-02-27 17:08:09.000000000 +0000
+++ lib/Test/More.pm    2003-02-27 17:25:20.000000000 +0000
@@ -1035,37 +1035,40 @@
         # Quiet uninitialized value warnings when comparing undefs.
         local $^W = 0; 
 
-        if( ! ref $e1 and ! ref $e2 and $e1 eq $e2 ) {
-            $ok = 1;
-        }
-        else {
-            if( UNIVERSAL::isa($e1, 'ARRAY') and
-                UNIVERSAL::isa($e2, 'ARRAY') )
+        if( ref($e1) eq ref($e2)) {
+
+            if( !ref($e1)) {
+                if ($e1 eq $e2) {
+                    $ok = 1;
+                }
+                else {
+                    push @Data_Stack, { vals => [$e1, $e2] };
+                    $ok = 0;
+                }
+            }
+            elsif( UNIVERSAL::isa($e1, 'ARRAY') )
             {
                 $ok = eq_array($e1, $e2);
             }
-            elsif( UNIVERSAL::isa($e1, 'HASH') and
-                   UNIVERSAL::isa($e2, 'HASH') )
+            elsif( UNIVERSAL::isa($e1, 'HASH') )
             {
                 $ok = eq_hash($e1, $e2);
             }
-            elsif( UNIVERSAL::isa($e1, 'REF') and
-                   UNIVERSAL::isa($e2, 'REF') )
+            elsif( UNIVERSAL::isa($e1, 'REF') )
             {
                 push @Data_Stack, { type => 'REF', vals => [$e1, $e2] };
                 $ok = _deep_check($$e1, $$e2);
                 pop @Data_Stack if $ok;
             }
-            elsif( UNIVERSAL::isa($e1, 'SCALAR') and
-                   UNIVERSAL::isa($e2, 'SCALAR') )
+            elsif( UNIVERSAL::isa($e1, 'SCALAR') )
             {
                 push @Data_Stack, { type => 'REF', vals => [$e1, $e2] };
                 $ok = _deep_check($$e1, $$e2);
             }
-            else {
-                push @Data_Stack, { vals => [$e1, $e2] };
-                $ok = 0;
-            }
+        }
+        else {
+            push @Data_Stack, { vals => [$e1, $e2] };
+            $ok = 0;
         }
     }
 


Reply via email to