| 1 | package TAP::Formatter::Base; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 19 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 19 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 19 | ▶ | use base 'TAP::Base'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 19 | ▶ | use POSIX qw(strftime); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 19 | my $MAX_ERRORS = 5; | |||||||||||||||||||||||||||||||
| 9 | 19 | my %VALIDATION_FOR; | |||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 19 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | %VALIDATION_FOR = ( | ||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | directives => sub { shift; shift }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 66 | ▶ | verbosity => sub { shift; shift }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | normalize => sub { shift; shift }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 16 | 43 | ▶ | timer => sub { shift; shift }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | 6 | ▶ | failures => sub { shift; shift }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | comments => sub { shift; shift }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | errors => sub { shift; shift }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 20 | 42 | ▶ | color => sub { shift; shift }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 21 | 90 | ▶ | jobs => sub { shift; shift }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | show_count => sub { shift; shift }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 23 | 15 | ▶ | stdout => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 24 | 15 | my ( $self, $ref ) = @_; | |||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 15 | ▶ | $self->_croak("option 'stdout' needs a filehandle") | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 27 | unless $self->_is_filehandle($ref); | ||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 13 | return $ref; | |||||||||||||||||||||||||||||||
| 30 | }, | ||||||||||||||||||||||||||||||||
| 31 | 19 | ); | |||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 15 | ▶ | sub _is_filehandle { | ||||||||||||||||||||||||||||||
|
Subroutine
_is_filehandle: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 34 | 15 | my ( $self, $ref ) = @_; | |||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | 15 | ▶ | return 0 if !defined $ref; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | 15 | ▶ | return 1 if ref $ref eq 'GLOB'; # lexical filehandle | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 39 | 13 | ▶ | return 1 if !ref $ref && ref \$ref eq 'GLOB'; # bare glob like *STDOUT | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not ref $ref and ref \$ref eq "GLOB"
MC/DC100%2/2
not ref $ref and ref \$ref eq "GLOB"
not ref $ref
ref \$ref eq "GLOB"
Truth table100%3/3
not(A) and B
A= not ref $refB= ref \$ref eq "GLOB"
| |||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | 12 | ▶ | return 1 if eval { $ref->can('print') }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 2 | return 0; | |||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 19 | my @getter_setters = qw( | |||||||||||||||||||||||||||||||
| 47 | _longest | ||||||||||||||||||||||||||||||||
| 48 | _printed_summary_header | ||||||||||||||||||||||||||||||||
| 49 | _colorizer | ||||||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | 19 | __PACKAGE__->mk_methods( @getter_setters, keys %VALIDATION_FOR ); | |||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | TAP::Formatter::Base - Base class for harness output delegates | ||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | =head1 VERSION | ||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | Version 3.52 | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | =cut | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | 19 | our $VERSION = '3.52'; | |||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | This provides console orientated output formatting for TAP::Harness. | ||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | use TAP::Formatter::Console; | ||||||||||||||||||||||||||||||||
| 74 | my $harness = TAP::Formatter::Console->new( \%args ); | ||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | =cut | ||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | 92 | ▶ | sub _initialize { | ||||||||||||||||||||||||||||||
|
Subroutine
_initialize: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||
| 79 | 92 | my ( $self, $arg_for ) = @_; | |||||||||||||||||||||||||||||||
| 80 | 92 | ▶ | $arg_for ||= {}; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$arg_for ||= {}
MC/DC100%1/1
$arg_for ||= {}
$arg_for
Truth table100%2/2
A
A= $arg_for
| |||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 92 | $self->SUPER::_initialize($arg_for); | |||||||||||||||||||||||||||||||
| 83 | 92 | my %arg_for = %$arg_for; # force a shallow copy | |||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | 92 | $self->verbosity(0); | |||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | 92 | for my $name ( keys %VALIDATION_FOR ) { | |||||||||||||||||||||||||||||||
| 88 | 1002 | my $property = delete $arg_for{$name}; | |||||||||||||||||||||||||||||||
| 89 | 1002 | ▶ | if ( defined $property ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 90 | 270 | my $validate = $VALIDATION_FOR{$name}; | |||||||||||||||||||||||||||||||
| 91 | 270 | $self->$name( $self->$validate($property) ); | |||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | 90 | ▶ | if ( my @props = keys %arg_for ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 96 | 0 | $self->_croak( | |||||||||||||||||||||||||||||||
| 97 | "Unknown arguments to " . __PACKAGE__ . "::new (@props)" ); | ||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | 90 | ▶ | $self->stdout( \*STDOUT ) unless $self->stdout; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | 90 | ▶ | if ( $self->color ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 103 | 2 | require TAP::Formatter::Color; | |||||||||||||||||||||||||||||||
| 104 | 2 | $self->_colorizer( TAP::Formatter::Color->new ); | |||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | 90 | return $self; | |||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | 12717 | ▶ | sub verbose { shift->verbosity >= 1 } | ||||||||||||||||||||||||||||||
|
Subroutine
verbose: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 111 | 12629 | ▶ | sub quiet { shift->verbosity <= -1 } | ||||||||||||||||||||||||||||||
|
Subroutine
quiet: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 112 | 198 | ▶ | sub really_quiet { shift->verbosity <= -2 } | ||||||||||||||||||||||||||||||
|
Subroutine
really_quiet: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 113 | 46 | ▶ | sub silent { shift->verbosity <= -3 } | ||||||||||||||||||||||||||||||
|
Subroutine
silent: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | =head1 METHODS | ||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | =head2 Class Methods | ||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | =head3 C<new> | ||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | my %args = ( | ||||||||||||||||||||||||||||||||
| 122 | verbose => 1, | ||||||||||||||||||||||||||||||||
| 123 | ) | ||||||||||||||||||||||||||||||||
| 124 | my $harness = TAP::Formatter::Console->new( \%args ); | ||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | The constructor returns a new C<TAP::Formatter::Console> object. If | ||||||||||||||||||||||||||||||||
| 127 | a L<TAP::Harness> is created with no C<formatter> a | ||||||||||||||||||||||||||||||||
| 128 | C<TAP::Formatter::Console> is automatically created. If any of the | ||||||||||||||||||||||||||||||||
| 129 | following options were given to TAP::Harness->new they well be passed to | ||||||||||||||||||||||||||||||||
| 130 | this constructor which accepts an optional hashref whose allowed keys are: | ||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||
| 132 | =over 4 | ||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | =item * C<verbosity> | ||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | Set the verbosity level. | ||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||
| 138 | =item * C<verbose> | ||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | Printing individual test results to STDOUT. | ||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | =item * C<timer> | ||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | Append run time for each test to output. Uses L<Time::HiRes> if available. | ||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||
| 146 | =item * C<failures> | ||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||
| 148 | Show test failures (this is a no-op if C<verbose> is selected). | ||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||
| 150 | =item * C<comments> | ||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||
| 152 | Show test comments (this is a no-op if C<verbose> is selected). | ||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||
| 154 | =item * C<quiet> | ||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||
| 156 | Suppressing some test output (mostly failures while tests are running). | ||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||
| 158 | =item * C<really_quiet> | ||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||
| 160 | Suppressing everything but the tests summary. | ||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||
| 162 | =item * C<silent> | ||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||
| 164 | Suppressing all output. | ||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||
| 166 | =item * C<errors> | ||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||
| 168 | If parse errors are found in the TAP output, a note of this will be made | ||||||||||||||||||||||||||||||||
| 169 | in the summary report. To see all of the parse errors, set this argument to | ||||||||||||||||||||||||||||||||
| 170 | true: | ||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||
| 172 | errors => 1 | ||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||
| 174 | =item * C<directives> | ||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||
| 176 | If set to a true value, only test results with directives will be displayed. | ||||||||||||||||||||||||||||||||
| 177 | This overrides other settings such as C<verbose>, C<failures>, or C<comments>. | ||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||
| 179 | =item * C<stdout> | ||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||
| 181 | A filehandle for catching standard output. | ||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||
| 183 | =item * C<color> | ||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||
| 185 | If defined specifies whether color output is desired. If C<color> is not | ||||||||||||||||||||||||||||||||
| 186 | defined it will default to color output if color support is available on | ||||||||||||||||||||||||||||||||
| 187 | the current platform and output is not being redirected. | ||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||
| 189 | =item * C<jobs> | ||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||
| 191 | The number of concurrent jobs this formatter will handle. | ||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||
| 193 | =item * C<show_count> | ||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||
| 195 | Boolean value. If false, disables the C<X/Y> test count which shows up while | ||||||||||||||||||||||||||||||||
| 196 | tests are running. | ||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||
| 198 | =back | ||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||
| 200 | Any keys for which the value is C<undef> will be ignored. | ||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||
| 202 | =cut | ||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||
| 204 | # new supplied by TAP::Base | ||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||
| 206 | =head3 C<prepare> | ||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||
| 208 | Called by Test::Harness before any test output is generated. | ||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||
| 210 | This is an advisory and may not be called in the case where tests are | ||||||||||||||||||||||||||||||||
| 211 | being supplied to Test::Harness by an iterator. | ||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||
| 213 | =cut | ||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||
| 215 | 77 | ▶ | sub prepare { | ||||||||||||||||||||||||||||||
|
Subroutine
prepare: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 216 | 77 | my ( $self, @tests ) = @_; | |||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||
| 218 | 77 | my $longest = 0; | |||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||
| 220 | 77 | for my $test (@tests) { | |||||||||||||||||||||||||||||||
| 221 | 162 | ▶ | $longest = length $test if length $test > $longest; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||
| 224 | 77 | $self->_longest($longest); | |||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | sub _format_now { strftime "[%H:%M:%S]", localtime } | ||||||||||||||||||||||||||||||
|
Subroutine
_format_now: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||
| 229 | 162 | ▶ | sub _format_name { | ||||||||||||||||||||||||||||||
|
Subroutine
_format_name: called CC=2 SCAR=7.5
| |||||||||||||||||||||||||||||||||
| 230 | 162 | my ( $self, $test ) = @_; | |||||||||||||||||||||||||||||||
| 231 | 162 | my $name = $test; | |||||||||||||||||||||||||||||||
| 232 | 162 | my $periods = '.' x ( $self->_longest + 2 - length $test ); | |||||||||||||||||||||||||||||||
| 233 | 162 | $periods = " $periods "; | |||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||
| 235 | 162 | ▶ | if ( $self->timer ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 236 | 0 | my $stamp = $self->_format_now(); | |||||||||||||||||||||||||||||||
| 237 | 0 | return "$stamp $name$periods"; | |||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||
| 239 | else { | ||||||||||||||||||||||||||||||||
| 240 | 162 | return "$name$periods"; | |||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||
| 245 | =head3 C<open_test> | ||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||
| 247 | Called to create a new test session. A test session looks like this: | ||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||
| 249 | my $session = $formatter->open_test( $test, $parser ); | ||||||||||||||||||||||||||||||||
| 250 | while ( defined( my $result = $parser->next ) ) { | ||||||||||||||||||||||||||||||||
| 251 | $session->result($result); | ||||||||||||||||||||||||||||||||
| 252 | exit 1 if $result->is_bailout; | ||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||
| 254 | $session->close_test; | ||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||
| 256 | =cut | ||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | sub open_test { | ||||||||||||||||||||||||||||||
|
Subroutine
open_test: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 259 | 0 | die "Unimplemented."; | |||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||
| 262 | 111 | ▶ | sub _output_success { | ||||||||||||||||||||||||||||||
|
Subroutine
_output_success: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 263 | 111 | my ( $self, $msg ) = @_; | |||||||||||||||||||||||||||||||
| 264 | 111 | $self->_output($msg); | |||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||
| 267 | =head3 C<summary> | ||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||
| 269 | $harness->summary( $aggregate ); | ||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||
| 271 | C<summary> prints the summary report after all tests are run. The first | ||||||||||||||||||||||||||||||||
| 272 | argument is an aggregate to summarise. An optional second argument may | ||||||||||||||||||||||||||||||||
| 273 | be set to a true value to indicate that the summary is being output as a | ||||||||||||||||||||||||||||||||
| 274 | result of an interrupted test run. | ||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||
| 276 | =cut | ||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||
| 278 | 46 | ▶ | sub summary { | ||||||||||||||||||||||||||||||
|
Subroutine
summary: called CC=15 SCAR=27.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 279 | 46 | my ( $self, $aggregate, $interrupted ) = @_; | |||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||
| 281 | 46 | ▶ | return if $self->silent; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||
| 283 | 40 | my @t = $aggregate->descriptions; | |||||||||||||||||||||||||||||||
| 284 | 40 | my $tests = \@t; | |||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||
| 286 | 40 | my $runtime = $aggregate->elapsed_timestr; | |||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||
| 288 | 40 | my $total = $aggregate->total; | |||||||||||||||||||||||||||||||
| 289 | 40 | my $passed = $aggregate->passed; | |||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||
| 291 | 40 | ▶ | if ( $self->timer ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 292 | 0 | $self->_output( $self->_format_now(), "\n" ); | |||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||
| 295 | 40 | ▶ | $self->_failure_output("Test run interrupted!\n") | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 296 | if $interrupted; | ||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||
| 298 | # TODO: Check this condition still works when all subtests pass but | ||||||||||||||||||||||||||||||||
| 299 | # the exit status is nonzero | ||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||
| 301 | 40 | ▶ | if ( $aggregate->all_passed ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 302 | 24 | $self->_output_success("All tests successful.\n"); | |||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||
| 305 | # ~TODO option where $aggregate->skipped generates reports | ||||||||||||||||||||||||||||||||
| 306 | 40 | ▶ | if ( $total != $passed or $aggregate->has_problems ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$total != $passed or $aggregate->has_problems
MC/DC100%2/2
$total != $passed or $aggregate->has_problems
$total != $passed
$aggregate->has_problems
Truth table100%3/3
A or B
A= $total != $passedB= $aggregate->has_problems
| |||||||||||||||||||||||||||||||||
| 307 | 17 | $self->_output("\nTest Summary Report"); | |||||||||||||||||||||||||||||||
| 308 | 17 | $self->_output("\n-------------------\n"); | |||||||||||||||||||||||||||||||
| 309 | 17 | for my $test (@$tests) { | |||||||||||||||||||||||||||||||
| 310 | 74 | $self->_printed_summary_header(0); | |||||||||||||||||||||||||||||||
| 311 | 74 | my ($parser) = $aggregate->parsers($test); | |||||||||||||||||||||||||||||||
| 312 | 74 | $self->_output_summary_failure( | |||||||||||||||||||||||||||||||
| 313 | 'failed', | ||||||||||||||||||||||||||||||||
| 314 | [ ' Failed test: ', ' Failed tests: ' ], | ||||||||||||||||||||||||||||||||
| 315 | $test, $parser | ||||||||||||||||||||||||||||||||
| 316 | ); | ||||||||||||||||||||||||||||||||
| 317 | 74 | $self->_output_summary_failure( | |||||||||||||||||||||||||||||||
| 318 | 'todo_passed', | ||||||||||||||||||||||||||||||||
| 319 | " TODO passed: ", $test, $parser | ||||||||||||||||||||||||||||||||
| 320 | ); | ||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||
| 322 | # ~TODO this cannot be the default | ||||||||||||||||||||||||||||||||
| 323 | #$self->_output_summary_failure( 'skipped', " Tests skipped: " ); | ||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||
| 325 | 74 | ▶ | if ( my $exit = $parser->exit ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 326 | 1 | $self->_summary_test_header( $test, $parser ); | |||||||||||||||||||||||||||||||
| 327 | 1 | $self->_failure_output(" Non-zero exit status: $exit\n"); | |||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||
| 329 | elsif ( my $wait = $parser->wait ) { | ||||||||||||||||||||||||||||||||
| 330 | 1 | $self->_summary_test_header( $test, $parser ); | |||||||||||||||||||||||||||||||
| 331 | 1 | $self->_failure_output(" Non-zero wait status: $wait\n"); | |||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||
| 334 | 74 | ▶ | if ( my @errors = $parser->parse_errors ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 335 | 5 | my $explain; | |||||||||||||||||||||||||||||||
| 336 | 5 | ▶ | if ( @errors > $MAX_ERRORS && !$self->errors ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@errors > $MAX_ERRORS and not $self->errors
MC/DC0%0/2
@errors > $MAX_ERRORS and not $self->errors
@errors > $MAX_ERRORS
not $self->errors
Truth table33%1/3
A and not(B)
A= @errors > $MAX_ERRORSB= not $self->errors
| |||||||||||||||||||||||||||||||||
| 337 | 0 | $explain | |||||||||||||||||||||||||||||||
| 338 | = "Displayed the first $MAX_ERRORS of " | ||||||||||||||||||||||||||||||||
| 339 | . scalar(@errors) | ||||||||||||||||||||||||||||||||
| 340 | . " TAP syntax errors.\n" | ||||||||||||||||||||||||||||||||
| 341 | . "Re-run prove with the -p option to see them all.\n"; | ||||||||||||||||||||||||||||||||
| 342 | 0 | splice @errors, $MAX_ERRORS; | |||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||
| 344 | 5 | $self->_summary_test_header( $test, $parser ); | |||||||||||||||||||||||||||||||
| 345 | 5 | $self->_failure_output( | |||||||||||||||||||||||||||||||
| 346 | sprintf " Parse errors: %s\n", | ||||||||||||||||||||||||||||||||
| 347 | shift @errors | ||||||||||||||||||||||||||||||||
| 348 | ); | ||||||||||||||||||||||||||||||||
| 349 | 5 | for my $error (@errors) { | |||||||||||||||||||||||||||||||
| 350 | 0 | my $spaces = ' ' x 16; | |||||||||||||||||||||||||||||||
| 351 | 0 | $self->_failure_output("$spaces$error\n"); | |||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||
| 353 | 5 | ▶ | $self->_failure_output($explain) if $explain; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||
| 357 | 40 | my $files = @$tests; | |||||||||||||||||||||||||||||||
| 358 | 40 | $self->_output("Files=$files, Tests=$total, $runtime\n"); | |||||||||||||||||||||||||||||||
| 359 | 40 | my $status = $aggregate->get_status; | |||||||||||||||||||||||||||||||
| 360 | 40 | $self->_output("Result: $status\n"); | |||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||
| 363 | 148 | ▶ | sub _output_summary_failure { | ||||||||||||||||||||||||||||||
|
Subroutine
_output_summary_failure: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 364 | 148 | my ( $self, $method, $name, $test, $parser ) = @_; | |||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||
| 366 | # ugly hack. Must rethink this :( | ||||||||||||||||||||||||||||||||
| 367 | 148 | ▶ | my $output = $method eq 'failed' ? '_failure_output' : '_output'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||
| 369 | 148 | ▶ | if ( my @r = $parser->$method() ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 370 | 14 | $self->_summary_test_header( $test, $parser ); | |||||||||||||||||||||||||||||||
| 371 | 14 | ▶ | my ( $singular, $plural ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 372 | = 'ARRAY' eq ref $name ? @$name : ( $name, $name ); | ||||||||||||||||||||||||||||||||
| 373 | 14 | ▶ | $self->$output( @r == 1 ? $singular : $plural ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 374 | 14 | my @results = $self->_balanced_range( 40, @r ); | |||||||||||||||||||||||||||||||
| 375 | 14 | $self->$output( sprintf "%s\n" => shift @results ); | |||||||||||||||||||||||||||||||
| 376 | 14 | my $spaces = ' ' x 16; | |||||||||||||||||||||||||||||||
| 377 | 14 | ▶ | while (@results) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 378 | 7 | $self->$output( sprintf "$spaces%s\n" => shift @results ); | |||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||
| 383 | 21 | ▶ | sub _summary_test_header { | ||||||||||||||||||||||||||||||
|
Subroutine
_summary_test_header: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||
| 384 | 21 | my ( $self, $test, $parser ) = @_; | |||||||||||||||||||||||||||||||
| 385 | 21 | ▶ | return if $self->_printed_summary_header; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 386 | 17 | my $spaces = ' ' x ( $self->_longest - length $test ); | |||||||||||||||||||||||||||||||
| 387 | 17 | ▶ | $spaces = ' ' unless $spaces; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 388 | 17 | my $output = $self->_get_output_method($parser); | |||||||||||||||||||||||||||||||
| 389 | 17 | my $wait = $parser->wait; | |||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||
| 391 | 17 | ▶ | if (defined $wait) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 392 | 17 | my $signum = $wait & 0x7f; | |||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||
| 394 | 17 | my $description; | |||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||
| 396 | 17 | ▶ | if ($signum) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 397 | 1 | require Config; | |||||||||||||||||||||||||||||||
| 398 | 1 | my @names = split ' ', $Config::Config{'sig_name'}; | |||||||||||||||||||||||||||||||
| 399 | 1 | $description = "Signal: $names[$signum]"; | |||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||
| 401 | 1 | my $dumped = $wait & 0x80; | |||||||||||||||||||||||||||||||
| 402 | 1 | ▶ | $description .= ', dumped core' if $dumped; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||
| 404 | elsif ($wait != 0) { | ||||||||||||||||||||||||||||||||
| 405 | 1 | $description = sprintf 'exited %d', ($wait >> 8); | |||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||
| 408 | 17 | ▶ | $wait .= " ($description)" if $wait != 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||
| 410 | else { | ||||||||||||||||||||||||||||||||
| 411 | 0 | $wait = '(none)'; | |||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||
| 414 | 17 | $self->$output( | |||||||||||||||||||||||||||||||
| 415 | sprintf "$test$spaces(Wstat: %s Tests: %d Failed: %d)\n", | ||||||||||||||||||||||||||||||||
| 416 | $wait, $parser->tests_run, scalar $parser->failed | ||||||||||||||||||||||||||||||||
| 417 | ); | ||||||||||||||||||||||||||||||||
| 418 | 17 | $self->_printed_summary_header(1); | |||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||
| 421 | 315 | ▶ | sub _output { | ||||||||||||||||||||||||||||||
|
Subroutine
_output: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 422 | 315 | print { shift->stdout } @_; | |||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||
| 425 | 76 | ▶ | sub _failure_output { | ||||||||||||||||||||||||||||||
|
Subroutine
_failure_output: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 426 | 76 | my $self = shift; | |||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||
| 428 | 76 | $self->_output(@_); | |||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||
| 431 | 15 | ▶ | sub _balanced_range { | ||||||||||||||||||||||||||||||
|
Subroutine
_balanced_range: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||
| 432 | 15 | my ( $self, $limit, @range ) = @_; | |||||||||||||||||||||||||||||||
| 433 | 15 | @range = $self->_range(@range); | |||||||||||||||||||||||||||||||
| 434 | 15 | my $line = ""; | |||||||||||||||||||||||||||||||
| 435 | 15 | my @lines; | |||||||||||||||||||||||||||||||
| 436 | 15 | my $curr = 0; | |||||||||||||||||||||||||||||||
| 437 | 15 | ▶ | while (@range) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 438 | 82 | ▶ | if ( $curr < $limit ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 439 | 74 | my $range = ( shift @range ) . ", "; | |||||||||||||||||||||||||||||||
| 440 | 74 | $line .= $range; | |||||||||||||||||||||||||||||||
| 441 | 74 | $curr += length $range; | |||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||
| 443 | elsif (@range) { | ||||||||||||||||||||||||||||||||
| 444 | 8 | $line =~ s/, $//; | |||||||||||||||||||||||||||||||
| 445 | 8 | push @lines => $line; | |||||||||||||||||||||||||||||||
| 446 | 8 | $line = ''; | |||||||||||||||||||||||||||||||
| 447 | 8 | $curr = 0; | |||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||
| 450 | 15 | ▶ | if ($line) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 451 | 15 | $line =~ s/, $//; | |||||||||||||||||||||||||||||||
| 452 | 15 | push @lines => $line; | |||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||
| 454 | 15 | return @lines; | |||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||
| 457 | 16 | ▶ | sub _range { | ||||||||||||||||||||||||||||||
|
Subroutine
_range: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 458 | 16 | my ( $self, @numbers ) = @_; | |||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||
| 460 | # shouldn't be needed, but subclasses might call this | ||||||||||||||||||||||||||||||||
| 461 | 16 | @numbers = sort { $a <=> $b } @numbers; | |||||||||||||||||||||||||||||||
| 462 | 16 | my ( $min, @range ); | |||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||
| 464 | 16 | for my $i ( 0 .. $#numbers ) { | |||||||||||||||||||||||||||||||
| 465 | 83 | my $num = $numbers[$i]; | |||||||||||||||||||||||||||||||
| 466 | 83 | my $next = $numbers[ $i + 1 ]; | |||||||||||||||||||||||||||||||
| 467 | 83 | ▶ | if ( defined $next && $next == $num + 1 ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
defined $next and $next == $num + 1
MC/DC100%2/2
defined $next and $next == $num + 1
defined $next
$next == $num + 1
Truth table100%3/3
A and B
A= defined $nextB= $next == $num + 1
| |||||||||||||||||||||||||||||||||
| 468 | 6 | ▶ | if ( !defined $min ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 469 | 4 | $min = $num; | |||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||
| 472 | elsif ( defined $min ) { | ||||||||||||||||||||||||||||||||
| 473 | 4 | push @range => "$min-$num"; | |||||||||||||||||||||||||||||||
| 474 | 4 | undef $min; | |||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||
| 476 | else { | ||||||||||||||||||||||||||||||||
| 477 | 73 | push @range => $num; | |||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||
| 480 | 16 | return @range; | |||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||
| 483 | 17 | ▶ | sub _get_output_method { | ||||||||||||||||||||||||||||||
|
Subroutine
_get_output_method: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 484 | 17 | my ( $self, $parser ) = @_; | |||||||||||||||||||||||||||||||
| 485 | 17 | ▶ | return $parser->has_problems ? '_failure_output' : '_output'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||
| 488 | 19 | 1; | |||||||||||||||||||||||||||||||