1 package TAP::Formatter::Console::ParallelSession;
9 use base 'TAP::Formatter::Console::Session';
11 use constant WIDTH => 72; # Because Eric says
16 my ( $self, $arg_for ) = @_;
18 $self->SUPER::_initialize($arg_for);
19 my $formatter = $self->formatter;
21 # Horrid bodge. This creates our shared context per harness. Maybe
22 # TAP::Harness should give us this?
23 my $context = $shared{$formatter} ||= $self->_create_shared_context;
24 push @{ $context->{active} }, $self;
29 sub _create_shared_context {
40 TAP::Formatter::Console::ParallelSession - Harness output delegate for parallel console output
48 our $VERSION = '3.31';
52 This provides console orientated output formatting for L<TAP::Harness>
53 when run with multiple L<TAP::Harness/jobs>.
74 $self->formatter->_output( "\r" . ( ' ' x WIDTH ) . "\r" );
80 my $trailer = '... )===';
81 my $chop_length = WIDTH - length $trailer;
84 my ( $self, $refresh ) = @_;
86 return if $new_now == $now and !$refresh;
89 my $formatter = $self->formatter;
90 return if $formatter->really_quiet;
92 my $context = $shared{$formatter};
94 my $ruler = sprintf '===( %7d;%d ', $context->{tests}, $now - $start;
96 for my $active ( @{ $context->{active} } ) {
97 my $parser = $active->parser;
98 my $tests = $parser->tests_run;
99 my $planned = $parser->tests_planned || '?';
101 $ruler .= sprintf '%' . length($planned) . "d/$planned ", $tests;
103 chop $ruler; # Remove a trailing space
106 if ( length $ruler > WIDTH ) {
107 $ruler =~ s/(.{$chop_length}).*/$1$trailer/o;
110 $ruler .= '=' x ( WIDTH - length($ruler) );
112 $formatter->_output("\r$ruler");
117 Called by the harness for each line of TAP it receives .
122 my ( $self, $result ) = @_;
123 my $formatter = $self->formatter;
125 # my $really_quiet = $formatter->really_quiet;
126 # my $show_count = $self->_should_show_count;
128 if ( $result->is_test ) {
129 my $context = $shared{$formatter};
132 my $active = $context->{active};
133 if ( @$active == 1 ) {
135 # There is only one test, so use the serial output format.
136 return $self->SUPER::result($result);
139 $self->_output_ruler( $self->parser->tests_run == 1 );
141 elsif ( $result->is_bailout ) {
142 $formatter->_failure_output(
143 "Bailout called. Further testing stopped: "
144 . $result->explanation
149 =head3 C<clear_for_close>
153 sub clear_for_close {
155 my $formatter = $self->formatter;
156 return if $formatter->really_quiet;
157 my $context = $shared{$formatter};
158 if ( @{ $context->{active} } == 1 ) {
159 $self->SUPER::clear_for_close;
172 my $name = $self->name;
173 my $parser = $self->parser;
174 my $formatter = $self->formatter;
175 my $context = $shared{$formatter};
177 $self->SUPER::close_test;
179 my $active = $context->{active};
181 my @pos = grep { $active->[$_]->name eq $name } 0 .. $#$active;
183 die "Can't find myself" unless @pos;
184 splice @$active, $pos[0], 1;
186 if ( @$active > 1 ) {
187 $self->_output_ruler(1);
189 elsif ( @$active == 1 ) {
191 # Print out "test/name.t ...."
192 $active->[0]->SUPER::header;
196 # $self->formatter->_output("\n");
197 delete $shared{$formatter};