5 # Test glob operations.
32 # Test fake references.
39 # Test real references.
46 # Test references to real arrays.
54 push(@{$ref[$i]}, "ok $ary[$i]\n");
61 # Test references to references.
67 # Test nested anonymous lists.
69 $ref = [[],2,[3,4,5,]];
70 print scalar @$ref == 3 ? "ok 14\n" : "not ok 14\n";
71 print $$ref[1] == 2 ? "ok 15\n" : "not ok 15\n";
72 print ${$$ref[2]}[2] == 5 ? "ok 16\n" : "not ok 16\n";
73 print scalar @{$$ref[0]} == 0 ? "ok 17\n" : "not ok 17\n";
75 print $ref->[1] == 2 ? "ok 18\n" : "not ok 18\n";
76 print $ref->[2]->[0] == 3 ? "ok 19\n" : "not ok 19\n";
78 # Test references to hashes of references.
81 $refref->{"key"} = $ref;
82 print $refref->{"key"}->[2]->[0] == 3 ? "ok 20\n" : "not ok 20\n";
84 # Test to see if anonymous subarrays spring into existence.
86 $spring[5]->[0] = 123;
87 $spring[5]->[1] = 456;
88 push(@{$spring[5]}, 789);
89 print join(':',@{$spring[5]}) eq "123:456:789" ? "ok 21\n" : "not ok 21\n";
91 # Test to see if anonymous subhashes spring into existence.
93 @{$spring2{"foo"}} = (1,2,3);
94 $spring2{"foo"}->[3] = 4;
95 print join(':',@{$spring2{"foo"}}) eq "1:2:3:4" ? "ok 22\n" : "not ok 22\n";
97 # Test references to subroutines.
99 sub mysub { print "ok 23\n" }
103 $subrefref = \\&mysub2;
104 $$subrefref->("ok 24\n");
105 sub mysub2 { print shift }
107 # Test the ref operator.
109 print ref $subref eq CODE ? "ok 25\n" : "not ok 25\n";
110 print ref $ref eq ARRAY ? "ok 26\n" : "not ok 26\n";
111 print ref $refref eq HASH ? "ok 27\n" : "not ok 27\n";
113 # Test anonymous hash syntax.
116 print ref $anonhash eq HASH ? "ok 28\n" : "not ok 28\n";
117 $anonhash2 = {FOO => BAR, ABC => XYZ,};
118 print join('', sort values %$anonhash2) eq BARXYZ ? "ok 29\n" : "not ok 29\n";
120 # Test bless operator.
124 $object = bless $main'anonhash2;
125 print ref $object eq MYHASH ? "ok 30\n" : "not ok 30\n";
126 print $object->{ABC} eq XYZ ? "ok 31\n" : "not ok 31\n";
129 print ref $object2 eq MYHASH ? "ok 32\n" : "not ok 32\n";
131 # Test ordinary call on object method.
133 &mymethod($object,33);
136 local($THIS, @ARGS) = @_;
137 die 'Got a "' . ref($THIS). '" instead of a MYHASH'
138 unless ref $THIS eq MYHASH;
139 print $THIS->{FOO} eq BAR ? "ok $ARGS[0]\n" : "not ok $ARGS[0]\n";
142 # Test automatic destructor call.
144 $string = "not ok 34\n";
147 $main'anonhash2 = "foo";
151 return unless $string;
154 # Test that the object has not already been "cursed".
155 print ref shift ne HASH ? "ok 35\n" : "not ok 35\n";
158 # Now test inheritance of methods.
164 $main'object = bless {FOO => foo, BAR => bar};
168 # Test arrow-style method invocation.
170 print $object->doit("BAR") eq bar ? "ok 36\n" : "not ok 36\n";
172 # Test indirect-object-style method invocation.
174 $foo = doit $object "FOO";
175 print $foo eq foo ? "ok 37\n" : "not ok 37\n";
179 die "Not an OBJ" unless ref $ref eq OBJ;
187 sub foo { print $_[1] }
190 foo WHATEVER "ok 38\n";
193 # test the \(@foo) construct
198 @baz = \(1,@foo,@bar);
199 print @bar == 3 ? "ok 39\n" : "not ok 39\n";
200 print grep(ref($_), @bar) == 3 ? "ok 40\n" : "not ok 40\n";
201 print @baz == 3 ? "ok 41\n" : "not ok 41\n";
205 my(@bzz) = \(1,@fuu,@baa);
206 print @baa == 3 ? "ok 42\n" : "not ok 42\n";
207 print grep(ref($_), @baa) == 3 ? "ok 43\n" : "not ok 43\n";
208 print @bzz == 3 ? "ok 44\n" : "not ok 44\n";
210 # test for proper destruction of lexical objects
212 sub larry::DESTROY { print "# larry\nok 45\n"; }
213 sub curly::DESTROY { print "# curly\nok 46\n"; }
214 sub moe::DESTROY { print "# moe\nok 47\n"; }
217 my ($joe, @curly, %larry);
218 my $moe = bless \$joe, 'moe';
219 my $curly = bless \@curly, 'curly';
220 my $larry = bless \%larry, 'larry';
221 print "# leaving block\n";
224 print "# left block\n";
229 { local(*bar) = "foo" }
238 # test if reblessing during destruction results in more destruction
242 sub new { bless {}, shift }
243 DESTROY { print "# destroying 'A'\nok 51\n" }
245 sub new { bless {}, shift }
246 DESTROY { print "# destroying '_B'\nok 50\n"; bless shift, 'A' }
251 # test if $_[0] is properly protected in DESTROY()
255 local $SIG{'__DIE__'} = sub {
258 print "# infinite recursion, bailing\nnot ok 52\n";
262 if ($m =~ /^Modification of a read-only/) { print "ok 52\n" }
265 sub new { bless {}, shift }
266 DESTROY { $_[0] = 'foo' }
268 print "# should generate an error...\n";
271 print "# good, didn't recurse\n";
274 # test if refgen behaves with autoviv magic
282 # This test is the reason for postponed destruction in sv_unref
285 print "not " unless $a == 2;
288 sub x::DESTROY {print "ok ", 54 + shift->[0], "\n"}
289 { my $a1 = bless [4],"x";
290 my $a2 = bless [3],"x";
291 { my $a3 = bless [2],"x";
292 my $a4 = bless [1],"x";
298 # test global destruction
301 my $test1 = $test + 1;
302 my $test2 = $test + 2;
307 $ref3 = bless ["ok $test2\n"]; # package destruction
308 my $ref2 = bless ["ok $test1\n"]; # lexical destruction
309 local $ref1 = bless ["ok $test\n"]; # dynamic destruction
310 1; # flush any temp values on stack