Avoid potentially empty struct.
[p5sagit/p5-mst-13.2.git] / t / op / tiearray.t
index da25760..337aff6 100755 (executable)
@@ -101,7 +101,7 @@ sub SPLICE
 
 package main;
 
-print "1..29\n";                   
+print "1..36\n";                   
 my $test = 1;
 
 {my @ary;
@@ -130,10 +130,19 @@ print "ok ", $test++,"\n";
 
 print "not " unless $seen{'STORE'} >= 3;
 print "ok ", $test++,"\n";
-
 print "not " unless join(':',@ary) eq '1:2:3';
 print "ok ", $test++,"\n";         
 
+{my @thing = @ary;
+print "not " unless join(':',@thing) eq '1:2:3';
+print "ok ", $test++,"\n";         
+
+tie @thing,'Implement';
+@thing = @ary;
+print "not " unless join(':',@thing) eq '1:2:3';
+print "ok ", $test++,"\n";
+} 
+
 print "not " unless pop(@ary) == 3;
 print "ok ", $test++,"\n";
 print "not " unless $seen{'POP'} == 1;
@@ -178,6 +187,7 @@ print "ok ", $test++,"\n";
 @ary = split(/:/,'1:2:3');
 print "not " unless join(':',@ary) eq '1:2:3';
 print "ok ", $test++,"\n";         
+
   
 my $t = 0;
 foreach $n (@ary)
@@ -186,6 +196,25 @@ foreach $n (@ary)
   print "ok ", $test++,"\n";         
  }
 
+# (30-33) 20020303 mjd-perl-patch+@plover.com
+@ary = ();
+$seen{POP} = 0;
+pop @ary;                       # this didn't used to call POP at all
+print "not " unless $seen{POP} == 1;
+print "ok ", $test++,"\n";         
+$seen{SHIFT} = 0;
+shift @ary;                     # this didn't used to call SHIFT at  all
+print "not " unless $seen{SHIFT} == 1;
+print "ok ", $test++,"\n";         
+$seen{PUSH} = 0;
+push @ary;                       # this didn't used to call PUSH at all
+print "not " unless $seen{PUSH} == 1;
+print "ok ", $test++,"\n";         
+$seen{UNSHIFT} = 0;
+unshift @ary;                   # this didn't used to call UNSHIFT at all
+print "not " unless $seen{UNSHIFT} == 1;
+print "ok ", $test++,"\n";         
+
 @ary = qw(3 2 1);
 print "not " unless join(':',@ary) eq '3:2:1';
 print "ok ", $test++,"\n";         
@@ -193,9 +222,25 @@ print "ok ", $test++,"\n";
 untie @ary;   
 
 }
-                           
-print "not " unless $seen{'DESTROY'} == 1;
-print "ok ", $test++,"\n";         
 
+# 20020401 mjd-perl-patch+@plover.com
+# Thanks to Dave Mitchell for the small test case and the fix
+{
+  my @a;
+  
+  sub X::TIEARRAY { bless {}, 'X' }
 
+  sub X::SPLICE {
+    do '/dev/null';
+    die;
+  }
+
+  tie @a, 'X';
+  eval { splice(@a) };
+  # If we survived this far.
+  print "ok ", $test++, "\n";
+}
+                           
+print "not " unless $seen{'DESTROY'} == 2;
+print "ok ", $test++,"\n";