| 1 | package TAP::Formatter::Console; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 5 | ▶ | use base 'TAP::Formatter::Base'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 5 | ▶ | use POSIX qw(strftime); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | TAP::Formatter::Console - Harness output delegate for default console output | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | =head1 VERSION | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | Version 3.52 | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 5 | our $VERSION = '3.52'; | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | =head1 DESCRIPTION | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | This provides console orientated output formatting for TAP::Harness. | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | =head1 SYNOPSIS | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | use TAP::Formatter::Console; | ||||||||||||||||||||
| 27 | my $harness = TAP::Formatter::Console->new( \%args ); | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | =head2 C<< open_test >> | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | See L<TAP::Formatter::Base> | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | =cut | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 15 | ▶ | sub open_test { | ||||||||||||||||||
|
Subroutine
open_test: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||
| 36 | 15 | my ( $self, $test, $parser ) = @_; | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 15 | ▶ | my $class | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | = $self->jobs > 1 | ||||||||||||||||||||
| 40 | ? 'TAP::Formatter::Console::ParallelSession' | ||||||||||||||||||||
| 41 | : 'TAP::Formatter::Console::Session'; | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 15 | eval "require $class"; | |||||||||||||||||||
| 44 | 15 | ▶ | $self->_croak($@) if $@; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 15 | my $session = $class->new( | |||||||||||||||||||
| 47 | { name => $test, | ||||||||||||||||||||
| 48 | formatter => $self, | ||||||||||||||||||||
| 49 | parser => $parser, | ||||||||||||||||||||
| 50 | show_count => $self->show_count, | ||||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 15 | $session->header; | |||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 15 | return $session; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | # Use _colorizer delegate to set output color. NOP if we have no delegate | ||||||||||||||||||||
| 60 | 99 | ▶ | sub _set_colors { | ||||||||||||||||||
|
Subroutine
_set_colors: called CC=4 SCAR=13.9
| |||||||||||||||||||||
| 61 | 99 | my ( $self, @colors ) = @_; | |||||||||||||||||||
| 62 | 99 | ▶ | if ( my $colorizer = $self->_colorizer ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 63 | 53 | ▶ | my $output_func = $self->{_output_func} ||= sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 64 | 53 | $self->_output(@_); | |||||||||||||||||||
| 65 | 53 | ▶ | }; | ||||||||||||||||||
|
Condition66%2/3
$self->{"_output_func"} ||= sub {
$self->_output(@_);
}
MC/DC0%0/2
$self->{"_output_func"} ||= sub {
$self->_output(@_);
}
$self->{"_output_func"}
sub {
$self->_output(@_);
}
Truth table66%2/3
A ||= B
A= $self->{"_output_func"}B= sub {
$self->_output(@_);
}
| |||||||||||||||||||||
| 66 | 53 | $colorizer->set_color( $output_func, $_ ) for @colors; | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 27 | ▶ | sub _failure_color { | ||||||||||||||||||
|
Subroutine
_failure_color: called CC=2 SCAR=7.2
| |||||||||||||||||||||
| 71 | 27 | my ($self) = @_; | |||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 27 | ▶ | return $ENV{'HARNESS_SUMMARY_COLOR_FAIL'} || 'red'; | ||||||||||||||||||
|
Condition50%1/2
$ENV{'HARNESS_SUMMARY_COLOR_FAIL'} || 'red'
MC/DC0%0/1
$ENV{'HARNESS_SUMMARY_COLOR_FAIL'} || 'red'
$ENV{'HARNESS_SUMMARY_COLOR_FAIL'}
Truth table50%1/2
A
A= $ENV{'HARNESS_SUMMARY_COLOR_FAIL'}
| |||||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 12 | ▶ | sub _success_color { | ||||||||||||||||||
|
Subroutine
_success_color: called CC=2 SCAR=7.2
| |||||||||||||||||||||
| 77 | 12 | my ($self) = @_; | |||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 12 | ▶ | return $ENV{'HARNESS_SUMMARY_COLOR_SUCCESS'} || 'green'; | ||||||||||||||||||
|
Condition50%1/2
$ENV{'HARNESS_SUMMARY_COLOR_SUCCESS'} || 'green'
MC/DC0%0/1
$ENV{'HARNESS_SUMMARY_COLOR_SUCCESS'} || 'green'
$ENV{'HARNESS_SUMMARY_COLOR_SUCCESS'}
Truth table50%1/2
A
A= $ENV{'HARNESS_SUMMARY_COLOR_SUCCESS'}
| |||||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 12 | ▶ | sub _output_success { | ||||||||||||||||||
|
Subroutine
_output_success: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 83 | 12 | my ( $self, $msg ) = @_; | |||||||||||||||||||
| 84 | 12 | $self->_set_colors( $self->_success_color() ); | |||||||||||||||||||
| 85 | 12 | $self->_output($msg); | |||||||||||||||||||
| 86 | 12 | $self->_set_colors('reset'); | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 27 | ▶ | sub _failure_output { | ||||||||||||||||||
|
Subroutine
_failure_output: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 90 | 27 | my $self = shift; | |||||||||||||||||||
| 91 | 27 | $self->_set_colors( $self->_failure_color() ); | |||||||||||||||||||
| 92 | 27 | my $out = join '', @_; | |||||||||||||||||||
| 93 | 27 | my $has_newline = chomp $out; | |||||||||||||||||||
| 94 | 27 | $self->_output($out); | |||||||||||||||||||
| 95 | 27 | $self->_set_colors('reset'); | |||||||||||||||||||
| 96 | 27 | ▶ | $self->_output($/) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 97 | if $has_newline; | ||||||||||||||||||||
| 98 | } | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 5 | 1; | |||||||||||||||||||