0f5022ce22d83ba646284e9e2ca7520853a4a72c
[p5sagit/Sub-Name.git] / t / smoke.t
1 use strict;
2 use warnings;
3
4 BEGIN { $^P |= 0x210 }
5
6 use Test::More;
7 use if $ENV{AUTHOR_TESTING}, 'Test::Warnings';
8 use Sub::Name;
9
10 my $x = subname foo => sub { (caller 0)[3] };
11 my $line = __LINE__ - 1;
12 my $file = __FILE__;
13 my $anon = $DB::sub{"main::__ANON__[${file}:${line}]"};
14
15 is($x->(), "main::foo");
16
17 package Blork;
18
19 use Sub::Name;
20
21 subname " Bar!", $x;
22 ::is($x->(), "Blork:: Bar!");
23
24 subname "Foo::Bar::Baz", $x;
25 ::is($x->(), "Foo::Bar::Baz");
26
27 subname "subname (dynamic $_)", \&subname  for 1 .. 3;
28
29 for (4 .. 5) {
30     subname "Dynamic $_", $x;
31     ::is($x->(), "Blork::Dynamic $_");
32 }
33
34 ::is($DB::sub{"main::foo"}, $anon);
35
36 for (4 .. 5) {
37     ::is($DB::sub{"Blork::Dynamic $_"}, $anon);
38 }
39
40 for ("Blork:: Bar!", "Foo::Bar::Baz") {
41     ::is($DB::sub{$_}, $anon);
42 }
43
44 ::done_testing();
45 # vim: ft=perl