This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Strengthen weak refs when sorting in-place
[perl5.git] / t / op / symbolcache.t
1 #!./perl -w
2
3 BEGIN {
4     chdir 't' if -d 't';
5     require './test.pl';
6     set_up_inc('../lib');
7 }
8
9 plan( tests => 8 );
10
11 use strict;
12
13 # first, with delete
14 # simple removal
15 sub removed { 23 }
16 sub bound { removed() }
17 delete $main::{removed};
18 is( bound(), 23, 'function still bound' );
19 ok( !main->can('removed'), 'function not available as method' );
20
21 # replacement
22 sub replaced { 'func' }
23 is( replaced(), 'func', 'original function still bound' );
24 is( main->replaced, 'meth', 'method is replaced function' );
25 BEGIN { delete $main::{replaced} }
26 sub replaced { 'meth' }
27
28 # and now with undef
29 # simple removal
30 sub removed2 { 24 }
31 sub bound2 { removed2() }
32 { no strict; undef *{"removed2"} }
33 eval { bound2() };
34 like( $@, qr/Undefined subroutine &main::removed2 called/,
35     'function not bound' );
36 ok( !main->can('removed2'), 'function not available as method' );
37
38 # replacement
39 sub replaced2 { 'func' }
40 is( replaced2(), 'meth', 'original function not bound, was replaced' );
41 ok( main->replaced2 eq 'meth', 'method is replaced function' );
42 BEGIN { undef $main::{replaced2} }
43 sub replaced2 { 'meth' }