RIP .travis.yml
[p5sagit/Sub-Name.git] / t / lexical.t
CommitLineData
d3b7b05c 1use strict;
2use warnings;
3
4use Test::More;
4d0e6f3d 5use if $ENV{AUTHOR_TESTING}, 'Test::Warnings';
d3b7b05c 6BEGIN {
7 if ("$]" < 5.018) {
8 plan 'skip_all' => 'lexical subs not supported on this perl';
9 }
10}
11
652bff51 12BEGIN {
13 if ("$]" < 5.020) {
14 plan 'skip_all' => 'lexical subs unreliable on this perl';
15 }
16}
17
d3b7b05c 18use feature 'lexical_subs';
19no warnings 'experimental::lexical_subs';
20
21use Sub::Name;
22
23local $TODO = "lexical subs unnameable until perl 5.22"
24 unless "$]" >= 5.022;
25
26my $foo = sub { (caller 0)[3] };
27
28my sub foo { (caller 0)[3] }
29
30subname 'main::foo2' => \&foo;
31is foo(), 'main::foo2', 'lexical subs can be named';
32
33my $x = 3;
34my sub bar { (caller 0)[$x] }
35subname 'main::bar2' => \&bar;
36is bar(), 'main::bar2', 'lexical closure subs can be named';
37
38done_testing;