X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fop%2Ftie.t;h=9a651555fc486444fe4ad5416cd114c39e1d7934;hb=95e8664e86da93255f26600f44bbbd70bf5b5b0e;hp=696a9265fb8d1d677fb738effb80534e250066dc;hpb=20822f61cc01ab34be1e17db483aceb9d5ec8fb7;p=p5sagit%2Fp5-mst-13.2.git diff --git a/t/op/tie.t b/t/op/tie.t index 696a926..9a65155 100755 --- a/t/op/tie.t +++ b/t/op/tie.t @@ -13,6 +13,7 @@ $|=1; # catch warnings into fatal errors $SIG{__WARN__} = sub { die "WARNING: @_" } ; +$SIG{__DIE__} = sub { die @_ }; undef $/; @prgs = split "\n########\n", ; @@ -25,7 +26,7 @@ for (@prgs){ $results = $@ ; $results =~ s/\n+$//; $expected =~ s/\n+$//; - if ( $status or $results and $results !~ /^WARNING: $expected/){ + if ( $status or $results and $results !~ /^(WARNING: )?$expected/){ print STDERR "STATUS: $status\n"; print STDERR "PROG: $prog\n"; print STDERR "EXPECTED:\n$expected\n"; @@ -44,6 +45,21 @@ untie %h; EXPECT ######## +# standard behaviour, without any extra references +use Tie::Hash ; +{package Tie::HashUntie; + use base 'Tie::StdHash'; + sub UNTIE + { + warn "Untied\n"; + } +} +tie %h, Tie::HashUntie; +untie %h; +EXPECT +Untied +######## + # standard behaviour, with 1 extra reference use Tie::Hash ; $a = tie %h, Tie::StdHash; @@ -146,17 +162,27 @@ $C = $B = tied %H ; untie %H; EXPECT ######## - -# verify no leak when underlying object is selfsame tied variable -my ($a, $b); +# Forbidden aggregate self-ties +my ($a, $b) = (0, 0); sub Self::TIEHASH { bless $_[1], $_[0] } -sub Self::DESTROY { $b = $_[0] + 0; } +sub Self::DESTROY { $b = $_[0] + 1; } { - my %b5; - $a = \%b5 + 0; - tie %b5, 'Self', \%b5; + my %c = 42; + tie %c, 'Self', \%c; } -die unless $a == $b; +EXPECT +Self-ties of arrays and hashes are not supported +######## +# Allowed scalar self-ties +my ($a, $b) = (0, 0); +sub Self::TIESCALAR { bless $_[1], $_[0] } +sub Self::DESTROY { $b = $_[0] + 1; } +{ + my $c = 42; + $a = $c + 0; + tie $c, 'Self', \$c; +} +die unless $a == 0 && $b == 43; EXPECT ######## # Interaction of tie and vec @@ -170,3 +196,9 @@ vec($a,1,1)=0; vec($b,1,1)=0; die unless $a eq $b; EXPECT +######## +# An attempt at lvalueable barewords broke this + +tie FH, 'main'; +EXPECT +