better to call require at runtime
[p5sagit/Sub-Name.git] / t / smoke.t
CommitLineData
3967e628 1BEGIN { print "1..10\n"; $^P |= 0x210 }
16c23894 2
16c23894 3use Sub::Name;
4
5my $x = subname foo => sub { (caller 0)[3] };
3967e628 6my $line = __LINE__ - 1;
7my $file = __FILE__;
8my $anon = $DB::sub{"main::__ANON__[${file}:${line}]"};
9
16c23894 10print $x->() eq "main::foo" ? "ok 1\n" : "not ok 1\n";
11
12
13package Blork;
14
15use Sub::Name;
16
17subname " Bar!", $x;
18print $x->() eq "Blork:: Bar!" ? "ok 2\n" : "not ok 2\n";
19
20subname "Foo::Bar::Baz", $x;
21print $x->() eq "Foo::Bar::Baz" ? "ok 3\n" : "not ok 3\n";
22
bbd01306 23subname "subname (dynamic $_)", \&subname for 1 .. 3;
24
25for (4 .. 5) {
26 subname "Dynamic $_", $x;
27 print $x->() eq "Blork::Dynamic $_" ? "ok $_\n" : "not ok $_\n";
28}
16c23894 29
3967e628 30print $DB::sub{"main::foo"} eq $anon ? "ok 6\n" : "not ok 6\n";
31
32for (4 .. 5) {
33 print $DB::sub{"Blork::Dynamic $_"} eq $anon ? "ok ".($_+3)."\n" : "not ok ".($_+3)."\n";
34}
35
36my $i = 9;
37for ("Blork:: Bar!", "Foo::Bar::Baz") {
38 print $DB::sub{$_} eq $anon ? "ok $i\n" : "not ok $_ \n";
39 $i++;
40}
41
16c23894 42# vim: ft=perl