This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Added porting tests for CUSTOMIZED files
[perl5.git] / t / op / current_sub.t
CommitLineData
84ed0108
FC
1#!./perl
2
3BEGIN {
4 chdir 't';
5 @INC = qw(../lib);
6 require './test.pl';
7}
8
9plan tests => 11;
10
11is __SUB__, "__SUB__", '__SUB__ is a bareword outside of use feature';
12
13{
14 use v5.15;
15 is __SUB__, undef, '__SUB__ under use v5.16';
16}
17
18use feature 'current_sub';
19
20is __SUB__, undef, '__SUB__ returns undef outside of a subroutine';
21is +()=__SUB__, 1, '__SUB__ returns undef in list context';
22
23sub foo { __SUB__ }
24is foo, \&foo, '__SUB__ inside a named subroutine';
25is foo->(), \&foo, '__SUB__ is callable';
26is ref foo, 'CODE', '__SUB__ is a code reference';
27
28my $subsub = sub { __SUB__ };
29is &$subsub, $subsub, '__SUB__ inside anonymous non-closure';
30
31my @subsubs;
32for my $x(1..3) {
33 push @subsubs, sub { return $x if @_; __SUB__ };
34}
35# Don’t loop here; we need to avoid interactions between the iterator
36# and the closure.
37is $subsubs[0]()(0), 1, '__SUB__ inside closure (1)';
38is $subsubs[1]()(0), 2, '__SUB__ inside closure (2)';
39is $subsubs[2]()(0), 3, '__SUB__ inside closure (3)';