magic.t tweak
[p5sagit/p5-mst-13.2.git] / t / op / ref.t
index 1d70f9f..4b1d6e3 100755 (executable)
@@ -1,6 +1,13 @@
 #!./perl
 
-print "1..55\n";
+BEGIN {
+    chdir 't' if -d 't';
+    @INC = qw(. ../lib);
+}
+
+print "1..62\n";
+
+require 'test.pl';
 
 # Test glob operations.
 
@@ -241,11 +248,11 @@ print $$_,"\n";
     package A;
     sub new { bless {}, shift }
     DESTROY { print "# destroying 'A'\nok 51\n" }
-    package B;
+    package _B;
     sub new { bless {}, shift }
-    DESTROY { print "# destroying 'B'\nok 50\n"; bless shift, 'A' }
+    DESTROY { print "# destroying '_B'\nok 50\n"; bless shift, 'A' }
     package main;
-    my $b = B->new;
+    my $b = _B->new;
 }
 
 # test if $_[0] is properly protected in DESTROY()
@@ -271,14 +278,55 @@ print $$_,"\n";
     print "# good, didn't recurse\n";
 }
 
+# test if refgen behaves with autoviv magic
+
+{
+    my @a;
+    $a[1] = "ok 53\n";
+    print ${\$_} for @a;
+}
+
+# This test is the reason for postponed destruction in sv_unref
+$a = [1,2,3];
+$a = $a->[1];
+print "not " unless $a == 2;
+print "ok 54\n";
+
+sub x::DESTROY {print "ok ", 54 + shift->[0], "\n"}
+{ my $a1 = bless [4],"x";
+  my $a2 = bless [3],"x";
+  { my $a3 = bless [2],"x";
+    my $a4 = bless [1],"x";
+    567;
+  }
+}
+
+
+my $result = runperl (switches=>['-l'],
+                      prog=> 'print 1; print qq-*$\*-;print 1;');
+my $expect = "1\n*\n*\n1\n";
+if ($result eq $expect) {
+  print "ok 59\n";
+} else {
+  print "not ok 59\n";
+  foreach ($expect, $result) {
+    s/\n/\\n/gs;
+  }
+  print "# expected \"$expect\", got \"$result\"\n";
+}
+
 # test global destruction
 
+my $test = 60;
+my $test1 = $test + 1;
+my $test2 = $test + 2;
+
 package FINALE;
 
 {
-    $ref3 = bless ["ok 55\n"];         # package destruction
-    my $ref2 = bless ["ok 54\n"];      # lexical destruction
-    local $ref1 = bless ["ok 53\n"];   # dynamic destruction
+    $ref3 = bless ["ok $test2\n"];     # package destruction
+    my $ref2 = bless ["ok $test1\n"];  # lexical destruction
+    local $ref1 = bless ["ok $test\n"];        # dynamic destruction
     1;                                 # flush any temp values on stack
 }