NineSec Team Shell
Server IP : 184.107.3.203  /  Your IP : 216.73.216.51
Web Server : Apache
System : Linux dedicated2.avenfashion.com.ph 4.18.0-553.40.1.el8_10.x86_64 #1 SMP Mon Feb 10 12:11:18 EST 2025 x86_64
User : adminteladeoro ( 1015)
PHP Version : 8.2.28
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /usr/share/doc/perl-Test-Simple/t/Test2/behavior/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //usr/share/doc/perl-Test-Simple/t/Test2/behavior/Formatter.t
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;

NineSec Team - 2022