File: basic.t

package info (click to toggle)
libtap-simpleoutput-perl 0.009-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 252 kB
  • sloc: perl: 249; makefile: 2
file content (102 lines) | stat: -rw-r--r-- 3,322 bytes parent folder | download | duplicates (4)
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
94
95
96
97
98
99
100
101
102
use strict;
use warnings;
use utf8;

use Test::More;
use TAP::SimpleOutput qw{ counters counters_as_hashref };

sub _check_level {
    my ($title, $counters, $level) = @_;

    my ($_ok, $_nok, $_skip, $_plan, $_todo, $_freeform) = @$counters;

    my @output;
    push @output, $_ok->('TestClass has a metaclass');
    push @output, $_skip->('TestClass is a Moose class');
    push @output, $_nok->('TestClass has an attribute named bar');
    push @output, $_ok->('TestClass has an attribute named baz');
    push @output, $_todo->($_ok->('TestClass has an attribute named foo'), 'next');
    push @output, $_freeform->('# hi there!');
    push @output, $_plan->();

    my $indent = !$level ? q{} : (' ' x (4*$level));

    my @expected = map { "$indent$_" } (
        qq{ok 1 - TestClass has a metaclass},
        qq{ok 2 # skip TestClass is a Moose class},
        qq{not ok 3 - TestClass has an attribute named bar},
        qq{ok 4 - TestClass has an attribute named baz},
        qq{ok 5 - TestClass has an attribute named foo # TODO next},
        qq{# hi there!},
        qq{1..5},
    );

    is_deeply
        [ @output   ],
        [ @expected ],
        "TAP output as expected: $title",
    ;
}

_check_level 'basic'   => [counters];
_check_level 'level 1' => [counters(1)], 1;

sub _as_hashref {
    my ($title, $out) = @_;

    # we're kinda cheating here a little bit, but really...  this is what we
    # need to test.
    my @counters = (
        $out->{ok},
        $out->{nok},
        $out->{skip},
        $out->{plan},
        $out->{todo},
        $out->{freeform},
    );
    _check_level $title => [@counters];
}

_as_hashref 'counters_as_hashref()' => counters_as_hashref;
_as_hashref 'scalar counters'       => scalar counters;

# levels and levels...
{
    my ($_ok, $_nok, $_skip, $_plan, $_todo) = counters();
    my @output;
    push @output, $_ok->('TestClass has a metaclass');
    push @output, $_skip->('TestClass is a Moose class');
    push @output, $_nok->('TestClass has an attribute named bar');
    push @output, $_ok->('TestClass has an attribute named baz');
    do {
        my ($_ok, $_nok, $_skip, $_plan) = counters(1);
        push @output, $_ok->(q{TestClass's attribute baz does TestRole::Two});
        push @output, $_ok->(q{TestClass's attribute baz has a reader});
        push @output, $_ok->(q{TestClass's attribute baz option reader correct});
        push @output, $_plan->();
    };
    push @output, $_ok->(q{[subtest] checking TestClass's attribute baz});
    push @output, $_todo->($_ok->('TestClass has an attribute named foo'), 'next');

    my @expected = (
        q{ok 1 - TestClass has a metaclass},
        q{ok 2 # skip TestClass is a Moose class},
        q{not ok 3 - TestClass has an attribute named bar},
        q{ok 4 - TestClass has an attribute named baz},
        q{    ok 1 - TestClass's attribute baz does TestRole::Two},
        q{    ok 2 - TestClass's attribute baz has a reader},
        q{    ok 3 - TestClass's attribute baz option reader correct},
        q{    1..3},
        q{ok 5 - [subtest] checking TestClass's attribute baz},
        q{ok 6 - TestClass has an attribute named foo # TODO next},
    );

    is_deeply
        [ @output   ],
        [ @expected ],
        'TAP output as expected',
        ;

}

done_testing;