Add a test that "eval" does not create additional reference to ouside variables.
[p5sagit/p5-mst-13.2.git] / t / op / smartmatch.t
index cb0e656..f8a073b 100644 (file)
@@ -11,15 +11,15 @@ no warnings 'uninitialized';
 
 use Tie::Array;
 use Tie::Hash;
-use Tie::RefHash;
+use if !$ENV{PERL_CORE_MINITEST}, "Tie::RefHash";
 
 # Predeclare vars used in the tests:
 my @empty;
 my %empty;
 my @sparse; $sparse[2] = 2;
 
-my $deep1 = []; push @$deep1, \$deep1;
-my $deep2 = []; push @$deep2, \$deep2;
+my $deep1 = []; push @$deep1, $deep1;
+my $deep2 = []; push @$deep2, $deep2;
 
 my @nums = (1..10);
 tie my @tied_nums, 'Tie::StdArray';
@@ -61,8 +61,11 @@ our $ov_obj_2 = Test::Object::WithOverload->new("object");
 our $obj = Test::Object::NoOverload->new;
 our $str_obj = Test::Object::StringOverload->new;
 
-tie my %refh, 'Tie::RefHash';
-$refh{$ov_obj} = 1;
+my %refh;
+if (!$ENV{PERL_CORE_MINITEST}) {
+    tie %refh, 'Tie::RefHash';
+    $refh{$ov_obj} = 1;
+}
 
 my @keyandmore = qw(key and more);
 my @fooormore = qw(foo or more);
@@ -70,9 +73,10 @@ my %keyandmore = map { $_ => 0 } @keyandmore;
 my %fooormore = map { $_ => 0 } @fooormore;
 
 # Load and run the tests
-plan tests => 322;
+plan tests => 335;
 
 while (<DATA>) {
+  SKIP: {
     next if /^#/ || !/\S/;
     chomp;
     my ($yn, $left, $right, $note) = split /\t+/;
@@ -88,6 +92,9 @@ while (<DATA>) {
     if ($note =~ /NOWARNINGS/) {
        $res = eval "no warnings; $tstr";
     }
+    elsif ($note =~ /MINISKIP/ && $ENV{PERL_CORE_MINITEST}) {
+       skip("Doesn't work with miniperl", $yn =~ /=/ ? 2 : 1);
+    }
     else {
        $res = eval $tstr;
     }
@@ -111,6 +118,7 @@ while (<DATA>) {
        $tstr = "$right ~~ $left";
        goto test_again;
     }
+  }
 }
 
 sub foo {}
@@ -302,11 +310,11 @@ __DATA__
 =      %hash           %tied_hash
        %tied_hash      %tied_hash
 !=     {"a"=>"b"}      %tied_hash
-       $ov_obj         %refh
-!      "$ov_obj"       %refh
-       [$ov_obj]       %refh
-!      ["$ov_obj"]     %refh
-       %refh           %refh
+       $ov_obj         %refh           MINISKIP
+!      "$ov_obj"       %refh           MINISKIP
+       [$ov_obj]       %refh           MINISKIP
+!      ["$ov_obj"]     %refh           MINISKIP
+       %refh           %refh           MINISKIP
 
 #  - an array ref
 #  (since this is symmetrical, tests as well hash~~array)
@@ -475,3 +483,18 @@ __DATA__
        @nums           {  1, '',  2, '' }
        @nums           {  1, '', 12, '' }
 !      @nums           { 11, '', 12, '' }
+
+# UNDEF
+!      3               undef
+!      1               undef
+!      []              undef
+!      {}              undef
+!      \%::main        undef
+!      [1,2]           undef
+!      %hash           undef
+!      @nums           undef
+!      "foo"           undef
+!      ""              undef
+!      !1              undef
+!      \&foo           undef
+!      sub { }         undef