This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
In test.pl, change like() and unlike() to avoid copying the tested scalar.
authorNicholas Clark <nick@ccl4.org>
Thu, 3 Mar 2011 08:30:16 +0000 (08:30 +0000)
committerNicholas Clark <nick@ccl4.org>
Sat, 5 Mar 2011 20:26:07 +0000 (20:26 +0000)
This means that side effects of matching regexps on it are maintained,
specifically the value of pos, making test.pl more useful for tests in t/re.

This is a subtle divergence from the behaviour of Test::More::{like,unlike}

t/test.pl

index 4087377..26605ca 100644 (file)
--- a/t/test.pl
+++ b/t/test.pl
@@ -325,12 +325,12 @@ sub like   ($$@) { like_yn (0,@_) }; # 0 for -
 sub unlike ($$@) { like_yn (1,@_) }; # 1 for un-
 
 sub like_yn ($$$@) {
-    my ($flip, $got, $expected, $name, @mess) = @_;
+    my ($flip, undef, $expected, $name, @mess) = @_;
     my $pass;
-    $pass = $got =~ /$expected/ if !$flip;
-    $pass = $got !~ /$expected/ if $flip;
+    $pass = $_[1] =~ /$expected/ if !$flip;
+    $pass = $_[1] !~ /$expected/ if $flip;
     unless ($pass) {
-       unshift(@mess, "#      got '$got'\n",
+       unshift(@mess, "#      got '$_[1]'\n",
                $flip
                ? "# expected !~ /$expected/\n" : "# expected /$expected/\n");
     }