]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blobdiff - t/40-localize_delete-target.t
Invalidate the method cache when localizing subroutines
[perl/modules/Scope-Upper.git] / t / 40-localize_delete-target.t
index c5abf9d8bbf7afcf39774c5afb4888adac229fac..044ca60b14c0f9dbed26146da2ccdf67285c1185 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 44 + 4;
+use Test::More tests => 53 + 4;
 
 use Scope::Upper qw/localize_delete UP HERE/;
 
@@ -162,7 +162,7 @@ our %h;
                        'localize_delete "%nonexistent", anything => HERE [end]';
 }
 
-# Others
+# Scalars
 
 our $x = 1;
 {
@@ -181,6 +181,8 @@ is $x, 1, 'localize_delete "$x", anything => HERE [end]';
                        'localize_delete "$nonexistent", anything => HERE [end]';
 }
 
+# Code
+
 sub x { 1 };
 {
  localize_delete '&x', 2 => HERE;
@@ -206,6 +208,50 @@ is x(), 1, 'localize_delete "&x", anything => HERE [end]';
 is x(), 1, 'localize_delete *x, anything => HERE [end 1]';
 is $x,  1, 'localize_delete *x, anything => HERE [end 2]';
 
+sub X::foo { 'X::foo' }
+
+{
+ {
+  {
+   localize_delete '&X::foo', undef => UP;
+   is(X->foo(), 'X::foo', 'localize_delete "&X::foo", undef => UP [not yet X]');
+  }
+  ok(!X->can('foo'), 'localize_delete "&X::foo", undef => UP [ok X]');
+ }
+ is(X->foo(), 'X::foo', 'localize_delete "&X::foo", undef => UP [end X]');
+}
+
+@Y::ISA = 'X';
+
+{
+ {
+  {
+   localize_delete '&X::foo', undef => UP;
+   is(Y->foo(), 'X::foo', 'localize_delete "&X::foo", undef => UP [not yet Y]');
+  }
+  ok(!Y->can('foo'), 'localize_delete "&X::foo", undef => UP [ok Y]');
+ }
+ is(Y->foo(), 'X::foo', 'localize_delete "&X::foo", undef => UP [end Y]');
+}
+
+
+{
+ local *Y::foo = sub { 'Y::foo' };
+ {
+  {
+   localize_delete '&Y::foo', undef => UP;
+   is(Y->foo(), 'Y::foo', 'localize_delete "&Y::foo", undef => UP [not yet]');
+  }
+  is(Y->foo(), 'X::foo', 'localize_delete "&Y::foo", undef => UP [ok]');
+ }
+ is(Y->foo(), 'Y::foo', 'localize_delete "&Y::foo", undef => UP [end]');
+}
+
+{
+ # Prevent 'only once' warnings
+ local *Y::foo = *Y::foo;
+}
+
 # Invalid
 
 sub invalid_ref { qr/^Invalid \Q$_[0]\E reference as the localization target/ }