summaryrefslogtreecommitdiff
path: root/cpan/Test-Simple/t/Modern/Builder_Provider.t
blob: 24956b32c481bd65fb8efba4432002726e361391 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use strict;
use warnings;

use Scalar::Util qw/reftype/;

{
    package My::Provider;
    use Test::Builder::Provider;
}

My::Provider->import();
my $anointed = __PACKAGE__->can('TB_TESTER_META');

require Test::More;
Test::More->import;

ok($anointed, "Importing our provider anointed us");

can_ok(
    'My::Provider',
    qw{
        TB_PROVIDER_META builder TB anoint gives give provides provide export
        import nest
    }
);

is(reftype(My::Provider->TB_PROVIDER_META), 'HASH', "Got Metadata");

isa_ok(My::Provider->builder, 'Test::Builder');
isa_ok(My::Provider->TB,      'Test::Builder');

{
    package My::Provider;

    provide foo => sub { 'foo' };
    provide hsh => { a => 1 };

    give xxx => sub { 'xxx' };
    give arr => [ 1 .. 5 ];

    provide nestx => sub(&) { TB->ok(&nest($_[0]), "Internal") };

    provides qw/bar baz/;
    gives    qw/aaa bbb/;

    provides qw/nesta nestb/;

    sub bar { 'bar' }
    sub baz { 'baz' }
    sub aaa { 'aaa' }
    sub bbb { 'bbb' }

    sub nesta { &nest($_->[0]) }
    sub nestb { &nest($_->[0]) }
}

My::Provider->import();

can_ok(
    __PACKAGE__,
    qw{ foo xxx nestx bar baz aaa bbb nesta nestb }
);

{
    no strict 'vars';
    no warnings 'once';
    is_deeply(\%hsh, { a => 1 }, "imported hash");
    is_deeply(\@arr, [ 1 .. 5 ], "imported array");
}

nestx(
    sub { ok(1, "Foo") }
);

done_testing();