This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
In ReTest.pl, convert iseq() and isneq() to the same logic as test.pl's is/isnt
authorNicholas Clark <nick@ccl4.org>
Wed, 2 Mar 2011 16:23:17 +0000 (16:23 +0000)
committerNicholas Clark <nick@ccl4.org>
Sat, 5 Mar 2011 20:26:08 +0000 (20:26 +0000)
Previously both would stringify first, then compare, which would mean that
any overloaded objects would have their stringify method called, instead of
'eq' or 'ne'.

t/re/ReTest.pl

index 4b480bb..ee147aa 100644 (file)
@@ -119,27 +119,41 @@ sub skip {
 }
 
 sub iseq ($$;$) { 
-    my ($got, $expect, $name) = @_;
-    
-    $_ = defined ($_) ? "'$_'" : "undef" for $got, $expect;
-        
-    my $ok    = $got eq $expect;
-    my $error = "# expected: $expect\n" .
+    my ($got, $expected, $name) = @_;
+
+    my $pass;
+    if(!defined $got || !defined $expected) {
+        # undef only matches undef
+        $pass = !defined $got && !defined $expected;
+    }
+    else {
+        $pass = $got eq $expected;
+    }
+
+    $_ = defined ($_) ? "'$_'" : "undef" for $got, $expected;
+
+    my $error = "# expected: $expected\n" .
                 "#   result: $got";
 
-    _ok $ok, $name, $error;
+    _ok $pass, $name, $error;
 }   
 
 sub isneq ($$;$) { 
-    my ($got, $expect, $name) = @_;
-    my $todo = $TODO ? " # TODO $TODO" : '';
-    
-    $_ = defined ($_) ? "'$_'" : "undef" for $got, $expect;
-        
-    my $ok    = $got ne $expect;
+    my ($got, $isnt, $name) = @_;
+
+    my $pass;
+    if(!defined $got || !defined $isnt) {
+        # undef only matches undef
+        $pass = defined $got || defined $isnt;
+    }
+    else {
+        $pass = $got ne $isnt;
+    }
+
+    $got = defined $got ? "'$got'" : "undef";
     my $error = "# results are equal ($got)";
 
-    _ok $ok, $name, $error;
+    _ok $pass, $name, $error;
 }