X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fop%2Fref.t;h=8ae90424eb87a5b5e04e7fe69e8ab121b09f1d3e;hb=a4c04bdcc508b6a45f83e703d0f82401445aa55b;hp=9fcc8ac15ceee3054ad137a1cac6838b7f5312e9;hpb=fb73857aa0bfa8ed43d4d2f972c564c70a57e0c4;p=p5sagit%2Fp5-mst-13.2.git diff --git a/t/op/ref.t b/t/op/ref.t index 9fcc8ac..8ae9042 100755 --- a/t/op/ref.t +++ b/t/op/ref.t @@ -1,6 +1,6 @@ #!./perl -print "1..51\n"; +print "1..61\n"; # Test glob operations. @@ -231,12 +231,82 @@ $bar = "ok 48"; local(*bar) = *bar; print "$bar\n"; +$var = "ok 49"; +$_ = \$var; +print $$_,"\n"; + +# test if reblessing during destruction results in more destruction + +{ + package A; + sub new { bless {}, shift } + DESTROY { print "# destroying 'A'\nok 51\n" } + package _B; + sub new { bless {}, shift } + DESTROY { print "# destroying '_B'\nok 50\n"; bless shift, 'A' } + package main; + my $b = _B->new; +} + +# test if $_[0] is properly protected in DESTROY() + +{ + my $i = 0; + local $SIG{'__DIE__'} = sub { + my $m = shift; + if ($i++ > 4) { + print "# infinite recursion, bailing\nnot ok 52\n"; + exit 1; + } + print "# $m"; + if ($m =~ /^Modification of a read-only/) { print "ok 52\n" } + }; + package C; + sub new { bless {}, shift } + DESTROY { $_[0] = 'foo' } + { + print "# should generate an error...\n"; + my $c = C->new; + } + 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; + } +} + + +# test global destruction + +my $test = 59; +my $test1 = $test + 1; +my $test2 = $test + 2; + package FINALE; { - $ref3 = bless ["ok 51\n"]; # package destruction - my $ref2 = bless ["ok 50\n"]; # lexical destruction - local $ref1 = bless ["ok 49\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 }