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