File: Squasher.t

package info (click to toggle)
perl 5.42.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 128,392 kB
  • sloc: perl: 534,963; ansic: 240,563; sh: 72,042; pascal: 6,934; xml: 2,428; yacc: 1,360; makefile: 1,197; cpp: 208; lisp: 1
file content (117 lines) | stat: -rw-r--r-- 3,869 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
use strict;
use warnings;

use Test2::Tools::Tiny;
use Test2::API::InterceptResult::Squasher;
use Test2::API::InterceptResult::Event;

my $CLASS = 'Test2::API::InterceptResult::Squasher';

my $trace1 = {pid => $$, tid => 0, cid => 1, frame => ['Foo::Bar', 'Foo/Bar.pm', 42, 'ok']};
my $trace2 = {pid => $$, tid => 0, cid => 2, frame => ['Foo::Bar', 'Foo/Bar.pm', 43, 'note']};
my $trace3 = {pid => $$, tid => 0, cid => 3, frame => ['Foo::Bar', 'Foo/Bar.pm', 44, 'subtest']};
my $trace4 = {pid => $$, tid => 0, cid => 4, frame => ['Foo::Bar', 'Foo/Bar.pm', 45, 'diag']};

my @raw = (
    # These 4 should merge
    Test2::API::InterceptResult::Event->new(facet_data => {
        trace => $trace1,
        info => [{tag => 'DIAG', details => 'about to fail'}],
    }),
    Test2::API::InterceptResult::Event->new(facet_data => {
        trace => $trace1,
        assert => { pass => 0, details => 'fail' },
    }),
    Test2::API::InterceptResult::Event->new(facet_data => {
        trace => $trace1,
        info => [{tag => 'DIAG', details => 'it failed'}],
    }),
    Test2::API::InterceptResult::Event->new(facet_data => {
        trace => $trace1,
        info => [{tag => 'DIAG', details => 'it failed part 2'}],
    }),

    # Same trace, but should not merge as it has an assert
    Test2::API::InterceptResult::Event->new(facet_data => {
        trace => $trace1,
        assert => { pass => 0, details => 'fail again' },
        info => [{tag => 'DIAG', details => 'it failed again'}],
    }),

    # Stand alone note
    Test2::API::InterceptResult::Event->new(facet_data => {
        trace => $trace2,
        info => [{tag => 'NOTE', details => 'Take Note!'}],
    }),

    # Subtest, note, assert, diag as 3 events, should be merged
    Test2::API::InterceptResult::Event->new(facet_data => {
        trace => $trace3,
        info => [{tag => 'NOTE', details => 'About to start subtest'}],
    }),
    Test2::API::InterceptResult::Event->new(facet_data => {
        trace => $trace3,
        assert => { pass => 0, details => 'failed subtest' },
        parent => { details => 'foo', state => {}, children => [] },
    }),
    Test2::API::InterceptResult::Event->new(facet_data => {
        trace => $trace3,
        info => [{tag => 'DIAG', details => 'Subtest failed'}],
    }),

    # Stand alone diag
    Test2::API::InterceptResult::Event->new(facet_data => {
        trace => $trace4,
        info => [{tag => 'DIAG', details => 'Diagnosis: Murder'}],
    }),
);

my @events;
my $squasher = $CLASS->new(events => \@events);
ok($squasher->isa($CLASS), "Got an instance");
$squasher->process($_) for @raw;
$squasher = undef;

is_deeply(
    [map { $_->facet_data } @events],
    [
        {
            trace  => $trace1,
            assert => {pass => 0, details => 'fail'},
            info   => [
                {tag => 'DIAG', details => 'about to fail'},
                {tag => 'DIAG', details => 'it failed'},
                {tag => 'DIAG', details => 'it failed part 2'},
            ],
        },

        {
            trace  => $trace1,
            assert => {pass => 0, details => 'fail again'},
            info   => [{tag => 'DIAG', details => 'it failed again'}],
        },

        {
            trace => $trace2,
            info  => [{tag => 'NOTE', details => 'Take Note!'}],
        },

        {
            trace  => $trace3,
            assert => {pass => 0, details => 'failed subtest'},
            parent => {details => 'foo', state => {}, children => []},
            info   => [
                {tag => 'NOTE', details => 'About to start subtest'},
                {tag => 'DIAG', details => 'Subtest failed'},
            ],
        },

        {
            trace => $trace4,
            info  => [{tag => 'DIAG', details => 'Diagnosis: Murder'}],
        },
    ],
    "Squashed events as expected"
);

done_testing;