refactor a bit
[gitmo/Package-Stash-XS.git] / t / addsub.t
CommitLineData
c53d2df2 1#!/usr/bin/env perl
4ada57e0 2use strict;
3use warnings;
c53d2df2 4use lib 't/lib';
4ada57e0 5use Test::More;
13f4d7c3 6use Test::Fatal;
4ada57e0 7
8BEGIN { $^P |= 0x210 } # PERLDBf_SUBLINE
9
10use Package::Stash;
11
12my $foo_stash = Package::Stash->new('Foo');
13
14# ----------------------------------------------------------------------
15## test adding a CODE
16
17ok(!defined($Foo::{funk}), '... the &funk slot has not been created yet');
18
20336547 19is(exception {
15c104e2 20 $foo_stash->add_symbol('&funk' => sub { "Foo::funk", __LINE__ });
20336547 21}, undef, '... created &Foo::funk successfully');
4ada57e0 22
23ok(defined($Foo::{funk}), '... the &funk slot was created successfully');
24
25{
26 no strict 'refs';
27 ok(defined &{'Foo::funk'}, '... our &funk exists');
28}
29
30is((Foo->funk())[0], 'Foo::funk', '... got the right value from the function');
31
32my $line = (Foo->funk())[1];
33is $DB::sub{'Foo::funk'}, sprintf "%s:%d-%d", __FILE__, $line, $line,
34 '... got the right %DB::sub value for funk default args';
35
15c104e2 36$foo_stash->add_symbol(
640de369 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';
45
46done_testing;