Add a test that "eval" does not create additional reference to ouside variables.
[p5sagit/p5-mst-13.2.git] / t / op / eval.t
index 2fef2aa..305d7f3 100644 (file)
@@ -6,7 +6,7 @@ BEGIN {
     require './test.pl';
 }
 
-print "1..99\n";
+print "1..105\n";
 
 eval 'print "ok 1\n";';
 
@@ -549,10 +549,48 @@ $test++;
 # don't leak memory
 {
     use feature qw(:5.10);
+    my $count_expected = ($^H & 0x20000) ? 2 : 1;
     my $t;
     my $s = "a";
     $s =~ s/a/$t = \%^H;  qq( qq() );/ee;
-    print "not " if Internals::SvREFCNT(%$t) != 1;
+    print "not " if Internals::SvREFCNT(%$t) != $count_expected;
     print "ok $test - RT 63110\n";
     $test++;
 }
+
+curr_test($test);
+
+{
+    # test that the CV compiled for the eval is freed by checking that no additional 
+    # reference to outside lexicals are made.
+    my $x;
+    is(Internals::SvREFCNT($x), 1, "originally only 1 referece");
+    eval '$x';
+    is(Internals::SvREFCNT($x), 1, "execution eval doesn't create new references");
+}
+
+fresh_perl_is(<<'EOP', "ok\n", undef, 'RT #70862');
+$::{'@'}='';
+eval {};
+print "ok\n";
+EOP
+
+fresh_perl_is(<<'EOP', "ok\n", undef, 'variant of RT #70862');
+eval {
+    $::{'@'}='';
+};
+print "ok\n";
+EOP
+
+fresh_perl_is(<<'EOP', "ok\n", undef, 'related to RT #70862');
+$::{'@'}=\3;
+eval {};
+print "ok\n";
+EOP
+
+fresh_perl_is(<<'EOP', "ok\n", undef, 'related to RT #70862');
+eval {
+    $::{'@'}=\3;
+};
+print "ok\n";
+EOP