diff options
author | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2007-02-24 09:53:56 +0000 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2007-02-24 09:53:56 +0000 |
commit | 446db2c1db07cb8824d05d0eac9f03ce91e4a749 (patch) | |
tree | 0230852e50aef1014640a8189f7e0719e07b58bc /t | |
parent | e8ae98db8e0325c510ea11398d7cf2a69dfcbcf7 (diff) | |
download | perl-446db2c1db07cb8824d05d0eac9f03ce91e4a749.tar.gz |
Add a new test for undef and delete on stash entries that
are bound to subroutines or methods. Based on a test by
Robert 'phaylon' Sedlacek.
p4raw-id: //depot/perl@30388
Diffstat (limited to 't')
-rw-r--r-- | t/op/symbolcache.t | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/t/op/symbolcache.t b/t/op/symbolcache.t new file mode 100644 index 0000000000..b3e567b0ca --- /dev/null +++ b/t/op/symbolcache.t @@ -0,0 +1,42 @@ +#!./perl -w + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; + require './test.pl'; + plan( tests => 8 ); +} + +use strict; + +# first, with delete +# simple removal +sub removed { 23 } +sub bound { removed() } +delete $main::{removed}; +is( bound(), 23, 'function still bound' ); +ok( !main->can('removed'), 'function not available as method' ); + +# replacement +sub replaced { 'func' } +is( replaced(), 'func', 'original function still bound' ); +is( main->replaced, 'meth', 'method is replaced function' ); +BEGIN { delete $main::{replaced} } +sub replaced { 'meth' } + +# and now with undef +# simple removal +sub removed2 { 24 } +sub bound2 { removed2() } +undef $main::{removed2}; +eval { bound2() }; +like( $@, qr/Undefined subroutine &main::removed2 called/, + 'function not bound' ); +ok( !main->can('removed2'), 'function not available as method' ); + +# replacement +sub replaced2 { 'func' } +is( replaced2(), 'meth', 'original function not bound, was replaced' ); +ok( main->replaced2 eq 'meth', 'method is replaced function' ); +BEGIN { undef $main::{replaced2} } +sub replaced2 { 'meth' } |