summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/perl/cpan/Test-Simple/t/Test2/modules/Event/Ok.t
blob: fa1121796574569969cb1ab001e841b36acf3082 (plain) (blame)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
use strict;
use warnings;

use Test2::Tools::Tiny;
use Test2::EventFacet::Trace;
use Test2::Event::Ok;
use Test2::Event::Diag;

use Test2::API qw/context/;

my $trace;
sub before_each {
    # Make sure there is a fresh trace object for each group
    $trace = Test2::EventFacet::Trace->new(
        frame => ['main_foo', 'foo.t', 42, 'main_foo::flubnarb'],
    );
}

tests Passing => sub {
    my $ok = Test2::Event::Ok->new(
        trace => $trace,
        pass  => 1,
        name  => 'the_test',
    );
    ok($ok->increments_count, "Bumps the count");
    ok(!$ok->causes_fail, "Passing 'OK' event does not cause failure");
    is($ok->pass, 1, "got pass");
    is($ok->name, 'the_test', "got name");
    is($ok->effective_pass, 1, "effective pass");
    is($ok->summary, "the_test", "Summary is just the name of the test");

    my $facet_data = $ok->facet_data;
    ok($facet_data->{about}, "got common facet data");
    ok(!$facet_data->{amnesty}, "No amnesty by default");
    is_deeply(
        $facet_data->{assert},
        {
            no_debug => 1,
            pass => 1,
            details => 'the_test',
        },
        "Got assert facet",
    );


    $ok = Test2::Event::Ok->new(
        trace => $trace,
        pass  => 1,
        name  => '',
    );
    is($ok->summary, "Nameless Assertion", "Nameless test");

    $facet_data = $ok->facet_data;
    ok($facet_data->{about}, "got common facet data");
    ok(!$facet_data->{amnesty}, "No amnesty by default");
    is_deeply(
        $facet_data->{assert},
        {
            no_debug => 1,
            pass => 1,
            details => '',
        },
        "Got assert facet",
    );
};

tests Failing => sub {
    local $ENV{HARNESS_ACTIVE} = 1;
    local $ENV{HARNESS_IS_VERBOSE} = 1;
    my $ok = Test2::Event::Ok->new(
        trace => $trace,
        pass  => 0,
        name  => 'the_test',
    );
    ok($ok->increments_count, "Bumps the count");
    ok($ok->causes_fail, "A failing test causes failures");
    is($ok->pass, 0, "got pass");
    is($ok->name, 'the_test', "got name");
    is($ok->effective_pass, 0, "effective pass");
    is($ok->summary, "the_test", "Summary is just the name of the test");

    my $facet_data = $ok->facet_data;
    ok($facet_data->{about}, "got common facet data");
    ok(!$facet_data->{amnesty}, "No amnesty by default");
    is_deeply(
        $facet_data->{assert},
        {
            no_debug => 1,
            pass => 0,
            details => 'the_test',
        },
        "Got assert facet",
    );
};

tests "Failing TODO" => sub {
    local $ENV{HARNESS_ACTIVE} = 1;
    local $ENV{HARNESS_IS_VERBOSE} = 1;
    my $ok = Test2::Event::Ok->new(
        trace => $trace,
        pass  => 0,
        name  => 'the_test',
        todo  => 'A Todo',
    );
    ok($ok->increments_count, "Bumps the count");
    is($ok->pass, 0, "got pass");
    is($ok->name, 'the_test', "got name");
    is($ok->effective_pass, 1, "effective pass is true from todo");
    is($ok->summary, "the_test (TODO: A Todo)", "Summary is just the name of the test + todo");

    my $facet_data = $ok->facet_data;
    ok($facet_data->{about}, "got common facet data");
    is_deeply(
        $facet_data->{assert},
        {
            no_debug => 1,
            pass => 0,
            details => 'the_test',
        },
        "Got assert facet",
    );
    is_deeply(
        $facet_data->{amnesty},
        [{
            tag => 'TODO',
            details => 'A Todo',
        }],
        "Got amnesty facet",
    );


    $ok = Test2::Event::Ok->new(
        trace => $trace,
        pass  => 0,
        name  => 'the_test2',
        todo  => '',
    );
    ok($ok->effective_pass, "empty string todo is still a todo");
    is($ok->summary, "the_test2 (TODO)", "Summary is just the name of the test + todo");

    $facet_data = $ok->facet_data;
    ok($facet_data->{about}, "got common facet data");
    is_deeply(
        $facet_data->{assert},
        {
            no_debug => 1,
            pass => 0,
            details => 'the_test2',
        },
        "Got assert facet",
    );
    is_deeply(
        $facet_data->{amnesty},
        [{
            tag => 'TODO',
            details => '',
        }],
        "Got amnesty facet",
    );

};

tests init => sub {
    my $ok = Test2::Event::Ok->new(
        trace => $trace,
        pass  => 1,
    );
    is($ok->effective_pass, 1, "set effective pass");
};

done_testing;