File: definition_context.t

package info (click to toggle)
libtest-moose-more-perl 0.050-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 512 kB
  • sloc: perl: 755; makefile: 2
file content (93 lines) | stat: -rw-r--r-- 2,304 bytes parent folder | download | duplicates (2)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use strict;
use warnings;

use Test::More;
use Test::Moose::More ':all';
use Test::Builder::Tester;
use TAP::SimpleOutput 0.009 'counters';

{
    package AAA;
    use Moose;

    has foo => (
        is => 'ro',
    );

    sub bar { }
}

subtest 'plain - method' => sub {
    definition_context_ok(AAA->meta->get_method('foo'), {
        context     => 'has declaration',
        description => 'reader AAA::foo',
        line        => 13,
        package     => 'AAA',
        type        => 'class',
        file        => __FILE__,
    });
};

subtest 'plain - attribute' => sub {
    definition_context_ok(AAA->meta->get_attribute('foo'), {
        context => 'has declaration',
        file    => __FILE__,
        line    => 13,
        package => 'AAA',
        type    => 'class'
    });
};

# NOTE begin Test::Builder::Tester tests

{
    my ($_ok, $_nok) = counters;

    test_out $_ok->('foo can definition_context()');
    test_out $_ok->('foo definition context is strictly correct');
    definition_context_ok(AAA->meta->get_attribute('foo'), {
        context => 'has declaration',
        file    => __FILE__,
        line    => 13,
        package => 'AAA',
        type    => 'class'
    });
    test_test 'output as expected';
}

{
    my ($_ok, $_nok) = counters;

    test_out $_ok->('foo can definition_context()');
    test_out $_nok->('foo definition context is strictly correct');
    test_err
        q{#   Failed test 'foo definition context is strictly correct'},
        qr{#   at .* line 69.\n},
        q{#     Structures begin differing at:},
        q{#          $got->{package} = 'AAA'},
        q{#     $expected->{package} = 'BBB'};
    definition_context_ok(AAA->meta->get_attribute('foo'), {
        context => 'has declaration',
        file    => __FILE__,
        line    => 13,
        package => 'BBB',
        type    => 'class'
    });
    test_test 'fail output as expected';
}
{
    my ($_ok, $_nok) = counters;

    test_out $_nok->('bar can definition_context()');
    test_fail 1;
    definition_context_ok(AAA->meta->get_method('bar'), {
        context => 'has declaration',
        file    => '-',
        line    => 13,
        package => 'AAA',
        type    => 'class'
    });
    test_test 'handles no definition_context()';
}

done_testing;