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