This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
add 1.875c to the list of supported bisons
[perl5.git] / t / op / loopctl.t
index a7416f2..bc326c7 100644 (file)
@@ -31,7 +31,7 @@
 #
 #  -- .robin. <robin@kitsite.com>  2001-03-13
 
-print "1..39\n";
+print "1..43\n";
 
 my $ok;
 
@@ -923,3 +923,47 @@ TEST39: {
     }
 }
 print ($ok ? "ok 39\n" : "not ok 39\n");
+
+
+### Test that loop control is dynamicly scoped.
+
+sub test_last_label { last TEST40 }
+
+TEST40: {
+    $ok = 1;
+    test_last_label();
+    $ok = 0;
+}
+print ($ok ? "ok 40\n" : "not ok 40\n");
+
+sub test_last { last }
+
+TEST41: {
+    $ok = 1;
+    test_last();
+    $ok = 0;
+}
+print ($ok ? "ok 41\n" : "not ok 41\n");
+
+
+# [perl #27206] Memory leak in continue loop
+# Ensure that the temporary object is freed each time round the loop,
+# rather then all 10 of them all being freed right at the end
+
+{
+    my $n=10; my $late_free = 0;
+    sub X::DESTROY { $late_free++ if $n < 0 };
+    {
+       ($n-- && bless {}, 'X') && redo;
+    }
+    print $late_free ? "not " : "", "ok 42 - redo memory leak\n";
+
+    $n = 10; $late_free = 0;
+    {
+       ($n-- && bless {}, 'X') && redo;
+    }
+    continue { }
+    print $late_free ? "not " : "", "ok 43 - redo with continue memory leak\n";
+}
+
+