NetWare port from Guruprasad S <SGURUPRASAD@novell.com>.
[p5sagit/p5-mst-13.2.git] / t / op / tie.t
index 451dee0..9a65155 100755 (executable)
@@ -6,13 +6,14 @@
 # Currently it only tests the untie warning 
 
 chdir 't' if -d 't';
-@INC = "../lib";
+@INC = '../lib';
 $ENV{PERL5LIB} = "../lib";
 
 $|=1;
 
 # catch warnings into fatal errors
 $SIG{__WARN__} = sub { die "WARNING: @_" } ;
+$SIG{__DIE__}  = sub { die @_ };
 
 undef $/;
 @prgs = split "\n########\n", <DATA>;
@@ -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;
@@ -77,8 +93,7 @@ EXPECT
 ########
 
 # strict behaviour, without any extra references
-use warning 'untie';
-#local $^W = 1 ;
+use warnings 'untie';
 use Tie::Hash ;
 tie %h, Tie::StdHash;
 untie %h;
@@ -86,8 +101,7 @@ EXPECT
 ########
 
 # strict behaviour, with 1 extra references generating an error
-use warning 'untie';
-#local $^W = 1 ;
+use warnings 'untie';
 use Tie::Hash ;
 $a = tie %h, Tie::StdHash;
 untie %h;
@@ -96,8 +110,7 @@ untie attempted while 1 inner references still exist
 ########
 
 # strict behaviour, with 1 extra references via tied generating an error
-use warning 'untie';
-#local $^W = 1 ;
+use warnings 'untie';
 use Tie::Hash ;
 tie %h, Tie::StdHash;
 $a = tied %h;
@@ -107,8 +120,7 @@ untie attempted while 1 inner references still exist
 ########
 
 # strict behaviour, with 1 extra references which are destroyed
-use warning 'untie';
-#local $^W = 1 ;
+use warnings 'untie';
 use Tie::Hash ;
 $a = tie %h, Tie::StdHash;
 $a = 0 ;
@@ -117,8 +129,7 @@ EXPECT
 ########
 
 # strict behaviour, with extra 1 references via tied which are destroyed
-use warning 'untie';
-#local $^W = 1 ;
+use warnings 'untie';
 use Tie::Hash ;
 tie %h, Tie::StdHash;
 $a = tied %h;
@@ -128,8 +139,7 @@ EXPECT
 ########
 
 # strict error behaviour, with 2 extra references 
-use warning 'untie';
-#local $^W = 1 ;
+use warnings 'untie';
 use Tie::Hash ;
 $a = tie %h, Tie::StdHash;
 $b = tied %h ;
@@ -139,14 +149,12 @@ untie attempted while 2 inner references still exist
 ########
 
 # strict behaviour, check scope of strictness.
-no warning 'untie';
-#local $^W = 0 ;
+no warnings 'untie';
 use Tie::Hash ;
 $A = tie %H, Tie::StdHash;
 $C = $B = tied %H ;
 {
-    use warning 'untie';
-    #local $^W = 1 ;
+    use warnings 'untie';
     use Tie::Hash ;
     tie %h, Tie::StdHash;
     untie %h;
@@ -154,15 +162,43 @@ $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
+
+my ($a, $b);
+use Tie::Scalar;
+tie $a,Tie::StdScalar or die;
+vec($b,1,1)=1;
+$a = $b;
+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
+