This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make __SUB__ work in special blocks
[perl5.git] / t / op / current_sub.t
index 7a00032..e72a0c5 100644 (file)
@@ -4,10 +4,9 @@ BEGIN {
     chdir 't';
     @INC = qw(../lib);
     require './test.pl';
+    plan (tests => 13);
 }
 
-plan tests => 11;
-
 is __SUB__, "__SUB__", '__SUB__ is a bareword outside of use feature';
 
 {
@@ -37,3 +36,12 @@ for my $x(1..3) {
 is $subsubs[0]()(0), 1, '__SUB__ inside closure (1)';
 is $subsubs[1]()(0), 2, '__SUB__ inside closure (2)';
 is $subsubs[2]()(0), 3, '__SUB__ inside closure (3)';
+
+BEGIN {
+    return "begin 1" if @_;
+    is CORE::__SUB__->(0), "begin 1", 'in BEGIN block'
+}
+BEGIN {
+    return "begin 2" if @_;
+    is &CORE::__SUB__->(0), "begin 2", 'in BEGIN block via & (unoptimised)'
+}