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
|
use strict;
use warnings;
use Test2::Tools::Tiny;
use Test2::API qw/intercept run_subtest test2_stack/;
use Test2::Event::Bail;
{
package Formatter::Subclass;
use base 'Test2::Formatter';
use Test2::Util::HashBase qw{f t};
sub init {
my $self = shift;
$self->{+F} = [];
$self->{+T} = [];
}
sub write { }
sub hide_buffered { 1 }
sub terminate {
my $s = shift;
push @{$s->{+T}}, [@_];
}
sub finalize {
my $s = shift;
push @{$s->{+F}}, [@_];
}
}
{
my $f = Formatter::Subclass->new;
intercept {
my $hub = test2_stack->top;
$hub->format($f);
is(1, 1, 'test event 1');
is(2, 2, 'test event 2');
is(3, 2, 'test event 3');
done_testing;
};
is(scalar @{$f->f}, 1, 'finalize method was called on formatter');
is_deeply(
$f->f->[0],
[3, 3, 1, 0, 0],
'finalize method received expected arguments'
);
ok(!@{$f->t}, 'terminate method was not called on formatter');
}
{
my $f = Formatter::Subclass->new;
intercept {
my $hub = test2_stack->top;
$hub->format($f);
$hub->send(Test2::Event::Bail->new(reason => 'everything is terrible'));
done_testing;
};
is(scalar @{$f->t}, 1, 'terminate method was called because of bail event');
ok(!@{$f->f}, 'finalize method was not called on formatter');
}
{
my $f = Formatter::Subclass->new;
intercept {
my $hub = test2_stack->top;
$hub->format($f);
$hub->send(Test2::Event::Plan->new(directive => 'skip_all', reason => 'Skipping all the tests'));
done_testing;
};
is(scalar @{$f->t}, 1, 'terminate method was called because of plan skip_all event');
ok(!@{$f->f}, 'finalize method was not called on formatter');
}
done_testing;
|