add_package_symbol (except the db bits, for now)
[gitmo/Package-Stash-XS.git] / t / 06-addsub.t
CommitLineData
4ada57e0 1use strict;
2use warnings;
3
4use Test::More;
13f4d7c3 5use Test::Fatal;
4ada57e0 6
7BEGIN { $^P |= 0x210 } # PERLDBf_SUBLINE
8
9use Package::Stash;
10
11my $foo_stash = Package::Stash->new('Foo');
12
13# ----------------------------------------------------------------------
14## test adding a CODE
15
16ok(!defined($Foo::{funk}), '... the &funk slot has not been created yet');
17
20336547 18is(exception {
4ada57e0 19 $foo_stash->add_package_symbol('&funk' => sub { "Foo::funk", __LINE__ });
20336547 20}, undef, '... created &Foo::funk successfully');
4ada57e0 21
22ok(defined($Foo::{funk}), '... the &funk slot was created successfully');
23
24{
25 no strict 'refs';
26 ok(defined &{'Foo::funk'}, '... our &funk exists');
27}
28
29is((Foo->funk())[0], 'Foo::funk', '... got the right value from the function');
30
31my $line = (Foo->funk())[1];
76f7c306 32{ local $TODO = "need to reimplement the db stuff in xs";
4ada57e0 33is $DB::sub{'Foo::funk'}, sprintf "%s:%d-%d", __FILE__, $line, $line,
34 '... got the right %DB::sub value for funk default args';
35
640de369 36$foo_stash->add_package_symbol(
37 '&dunk' => sub { "Foo::dunk" },
38 filename => "FileName",
39 first_line_num => 100,
40 last_line_num => 199
41);
4ada57e0 42
43is $DB::sub{'Foo::dunk'}, sprintf "%s:%d-%d", "FileName", 100, 199,
44 '... got the right %DB::sub value for dunk with specified args';
76f7c306 45}
4ada57e0 46
47done_testing;