]> git.vpit.fr Git - perl/modules/Sub-Op.git/blobdiff - t/11-existing.t
Test that the existing sub is called after ending the pragma scope
[perl/modules/Sub-Op.git] / t / 11-existing.t
index ecc673ef7738745f6d94bff143f8d2410f4f9ac2..2e6c6ca11a424a372f23e54c249e309926e70ad0 100644 (file)
@@ -5,7 +5,7 @@ use warnings;
 
 use blib 't/Sub-Op-LexicalSub';
 
-use Test::More tests => 2 *((4 + 2 * 4) + (2 * 5) + 1);
+use Test::More tests => 2 * ((2 + 2) * 4 + (1 + 2) * 5) + (2 + 2) + 4;
 
 our $call_foo;
 sub foo { ok $call_foo, 'the preexistent foo was called' }
@@ -13,6 +13,8 @@ sub foo { ok $call_foo, 'the preexistent foo was called' }
 our $call_bar;
 sub bar () { ok $call_bar, 'the preexistent bar was called' }
 
+sub X () { 1 }
+
 our $called;
 
 {
@@ -42,7 +44,7 @@ our $called;
    @seq = ($names[0]) x $calls;
   }
 
-  my $test = "{\n";
+  my $test = "{\n{\n";
   for my $name (@names) {
    $test .= <<"   INIT"
     use Sub::Op::LexicalSub $name => sub {
@@ -57,6 +59,15 @@ our $called;
   }
   $test .= "{\n$code\n}\n";
   $test .= "}\n";
+  for my $name (grep +{ map +($_, 1), qw/foo bar/ }->{ $_ }, @names) {
+   $test .= <<"   CHECK_SUB"
+    {
+     local \$call_$name = 1;
+     $name();
+    }
+   CHECK_SUB
+  }
+  $test .= "}\n";
 
   local $called = 0;
   eval $test;
@@ -67,13 +78,16 @@ our $called;
 
   is $called, $calls, "@names: the hook was called the right number of times";
   if ($called < $calls) {
-   fail for $called + 1 .. $calls;
+   fail, fail for $called + 1 .. $calls;
   }
  }
 }
 
 is prototype('main::foo'), undef, "foo's prototype was preserved";
 is prototype('main::bar'), '',    "bar's prototype was preserved";
+is prototype('main::X'),   '',    "X's prototype was preserved";
+ok Sub::Op::_constant_sub(do { no strict "refs"; \&{"main::X"} }),
+                                  'X is still a constant';
 
 __DATA__
 foo();
@@ -161,3 +175,7 @@ my $bar = \&bar;
 &$bar;
 ----
 bar # () #
+####
+is X, 2, 'constant overriding';
+----
+X # 2 # [ ]