3 # This test harness will (eventually) test the "tie" functionality
4 # without the need for a *DBM* implementation.
6 # Currently it only tests the untie warning
10 $ENV{PERL5LIB} = "../lib";
14 # catch warnings into fatal errors
15 $SIG{__WARN__} = sub { die "WARNING: @_" } ;
16 $SIG{__DIE__} = sub { die @_ };
19 @prgs = split "\n########\n", <DATA>;
20 print "1..", scalar @prgs, "\n";
23 my($prog,$expected) = split(/\nEXPECT\n/, $_);
28 $expected =~ s/\n+$//;
29 if ( $status or $results and $results !~ /^(WARNING: )?$expected/){
30 print STDERR "STATUS: $status\n";
31 print STDERR "PROG: $prog\n";
32 print STDERR "EXPECTED:\n$expected\n";
33 print STDERR "GOT:\n$results\n";
36 print "ok ", ++$i, "\n";
41 # standard behaviour, without any extra references
48 # standard behaviour, without any extra references
50 {package Tie::HashUntie;
51 use base 'Tie::StdHash';
57 tie %h, Tie::HashUntie;
63 # standard behaviour, with 1 extra reference
65 $a = tie %h, Tie::StdHash;
70 # standard behaviour, with 1 extra reference via tied
78 # standard behaviour, with 1 extra reference which is destroyed
80 $a = tie %h, Tie::StdHash;
86 # standard behaviour, with 1 extra reference via tied which is destroyed
95 # strict behaviour, without any extra references
103 # strict behaviour, with 1 extra references generating an error
104 use warnings 'untie';
106 $a = tie %h, Tie::StdHash;
109 untie attempted while 1 inner references still exist
112 # strict behaviour, with 1 extra references via tied generating an error
113 use warnings 'untie';
115 tie %h, Tie::StdHash;
119 untie attempted while 1 inner references still exist
122 # strict behaviour, with 1 extra references which are destroyed
123 use warnings 'untie';
125 $a = tie %h, Tie::StdHash;
131 # strict behaviour, with extra 1 references via tied which are destroyed
132 use warnings 'untie';
134 tie %h, Tie::StdHash;
141 # strict error behaviour, with 2 extra references
142 use warnings 'untie';
144 $a = tie %h, Tie::StdHash;
148 untie attempted while 2 inner references still exist
151 # strict behaviour, check scope of strictness.
154 $A = tie %H, Tie::StdHash;
157 use warnings 'untie';
159 tie %h, Tie::StdHash;
165 # Forbidden aggregate self-ties
166 my ($a, $b) = (0, 0);
167 sub Self::TIEHASH { bless $_[1], $_[0] }
168 sub Self::DESTROY { $b = $_[0] + 1; }
174 Self-ties of arrays and hashes are not supported
176 # Allowed scalar self-ties
177 my ($a, $b) = (0, 0);
178 sub Self::TIESCALAR { bless $_[1], $_[0] }
179 sub Self::DESTROY { $b = $_[0] + 1; }
185 die unless $a == 0 && $b == 43;
188 # Interaction of tie and vec
192 tie $a,Tie::StdScalar or die;