This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to Test-Harness-3.16
[perl5.git] / ext / Test-Harness / lib / TAP / Formatter / File / Session.pm
CommitLineData
bdaf8c65
SH
1package TAP::Formatter::File::Session;
2
3use strict;
4use TAP::Formatter::Session;
5
6use vars qw($VERSION @ISA);
7
8@ISA = qw(TAP::Formatter::Session);
9
10=head1 NAME
11
12TAP::Formatter::File::Session - Harness output delegate for file output
13
14=head1 VERSION
15
16Version 3.16
17
18=cut
19
20$VERSION = '3.16';
21
22=head1 DESCRIPTION
23
24This provides file orientated output formatting for L<TAP::Harness>.
25It is particularly important when running with parallel tests, as it
26ensures that test results are not interleaved, even when run
27verbosely.
28
29=cut
30
31=head1 METHODS
32
33=head2 result
34
35Stores results for later output, all together.
36
37=cut
38
39sub result {
40 my $self = shift;
41 my $result = shift;
42
43 my $parser = $self->parser;
44 my $formatter = $self->formatter;
45
46 if ( $result->is_bailout ) {
47 $formatter->_failure_output(
48 "Bailout called. Further testing stopped: "
49 . $result->explanation
50 . "\n" );
51 return;
52 }
53
54 if (!$formatter->quiet
55 && ( ( $formatter->verbose && !$formatter->failures )
56 || ( $result->is_test && $formatter->failures && !$result->is_ok )
57 || ( $result->has_directive && $formatter->directives ) )
58 )
59 {
60 $self->{results} .= $result->as_string . "\n";
61 }
62}
63
64=head2 close_test
65
66When the test file finishes, outputs the summary, together.
67
68=cut
69
70sub close_test {
71 my $self = shift;
72
73 # Avoid circular references
74 $self->parser(undef);
75
76 my $parser = $self->parser;
77 my $formatter = $self->formatter;
78 my $pretty = $formatter->_format_name( $self->name );
79
80 return if $formatter->really_quiet;
81 if ( my $skip_all = $parser->skip_all ) {
82 $formatter->_output( $pretty . "skipped: $skip_all\n" );
83 }
84 elsif ( $parser->has_problems ) {
85 $formatter->_output(
86 $pretty . ( $self->{results} ? "\n" . $self->{results} : "\n" ) );
87 $self->_output_test_failure($parser);
88 }
89 else {
90 my $time_report = '';
91 if ( $formatter->timer ) {
92 my $start_time = $parser->start_time;
93 my $end_time = $parser->end_time;
94 if ( defined $start_time and defined $end_time ) {
95 my $elapsed = $end_time - $start_time;
96 $time_report
97 = $self->time_is_hires
98 ? sprintf( ' %8d ms', $elapsed * 1000 )
99 : sprintf( ' %8s s', $elapsed || '<1' );
100 }
101 }
102
103 $formatter->_output( $pretty
104 . ( $self->{results} ? "\n" . $self->{results} : "" )
105 . "ok$time_report\n" );
106 }
107}
108
1091;