This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
tiearray.t - more fine-grained DESTROY counts
authorDavid Mitchell <davem@iabyn.com>
Fri, 21 Oct 2016 13:42:18 +0000 (14:42 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 26 Oct 2016 07:37:27 +0000 (08:37 +0100)
It currently tests once near the end of the script that DESTROY has been
called 3 times. Instead test after each individual scope exit
where we expect DESTROY to be called

t/op/tiearray.t

index b853594..1de4611 100644 (file)
@@ -6,6 +6,8 @@ BEGIN {
     set_up_inc('../lib');
 }
 
+plan(tests => 75);
+
 my %seen;
 
 package Implement;
@@ -135,9 +137,8 @@ sub FETCHSIZE { -1 }
 
 package main;
 
-plan(tests => 73);
-
 {
+    $seen{'DESTROY'} = 0;
     my @ary;
 
     {
@@ -164,6 +165,7 @@ plan(tests => 73);
         @thing = @ary;
         is(join(':',@thing), '1:2:3');
     }
+    is($seen{'DESTROY'}, 1, "thing freed");
 
     is(pop(@ary), 3);
     is($seen{'POP'}, 1);
@@ -228,6 +230,7 @@ plan(tests => 73);
 
     untie @ary;
 }
+is($seen{'DESTROY'}, 2, "ary freed");
 
 # 20020401 mjd-perl-patch+@plover.com
 # Thanks to Dave Mitchell for the small test case and the fix
@@ -249,6 +252,8 @@ plan(tests => 73);
 
 # 20020220 mjd-perl-patch+@plover.com
 {
+    $seen{'DESTROY'} = 0;
+
     my @n;
     tie @n => 'NegIndex', ('A' .. 'E');
 
@@ -279,6 +284,7 @@ plan(tests => 73);
         is(exists($n[$_]), '');
     }
 }
+is($seen{'DESTROY'}, 1, "n freed");
 
 {
     tie my @dummy, "NegFetchsize";
@@ -287,8 +293,6 @@ plan(tests => 73);
         " - croak on negative FETCHSIZE");
 }
 
-is($seen{'DESTROY'}, 3);
-
 {
     # check that a tied element assigned to an array doesn't remain tied