Possible parallel output

Nicholas Clark nick at ccl4.org
Thu Aug 28 14:47:06 UTC 2008


I was wondering about having an option to make the parallel test output
rule be something like:

===(  110631  0/?  1548/2309   1/52 )===================================

(that's total tests, as currently, plus the tickers for each active test).

Something like the appended patch, although it's hardwired, and it's not
quite perfect. (Refresh doesn't seem to work properly when a new test arrives.
I don't seem to be catching the '1' moment correctly).

What do people think?

Nicholas Clark

diff --git a/lib/TAP/Formatter/Console/ParallelSession.pm b/lib/TAP/Formatter/Console/ParallelSession.pm
index 69cf6ad..5691477 100644
--- a/lib/TAP/Formatter/Console/ParallelSession.pm
+++ b/lib/TAP/Formatter/Console/ParallelSession.pm
@@ -6,7 +6,12 @@ use File::Path;
 use TAP::Formatter::Console::Session;
 use Carp;
 
-use constant WIDTH => 72;    # Because Eric says
+use constant {WIDTH => 72,    # Because Eric says
+	      LEADER => '===( ', TRAILER => ' )===', TRIM_MARK => '...' };
+
+use constant MAX_RULER_CONTENT => WIDTH - length (LEADER . TRAILER);
+use constant RULER_CONTENT_TRIM => MAX_RULER_CONTENT - length TRIM_MARK;
+
 use vars qw($VERSION @ISA);
 
 @ISA = qw(TAP::Formatter::Console::Session);
@@ -85,16 +90,36 @@ sub _clear_line {
     $self->formatter->_output( "\r" . ( ' ' x WIDTH ) . "\r" );
 }
 
+my $now = 0;
+
 sub _output_ruler {
-    my $self      = shift;
+    my ($self, $refresh) = @_;
+    my $new_now = time;
+    return if $new_now == $now and !$refresh;
+    $now = $new_now;
     my $formatter = $self->formatter;
     return if $formatter->really_quiet;
 
+
     my $context = $shared{$formatter};
 
-    my $ruler = sprintf( "===( %7d )", $context->{tests} );
-    $ruler .= ( '=' x ( WIDTH - length $ruler ) );
-    $formatter->_output("\r$ruler");
+    my $ruler = sprintf '%7d  ', $context->{tests};
+
+    foreach my $active ( @{$context->{active}} ) {
+	my $parser = $active->parser;
+	my $tests = $parser->tests_run;
+	my $planned = $parser->tests_planned || '?';
+
+	$ruler .= sprintf '%' . length ($planned) . "d/$planned  ", $tests;
+    }
+    chop $ruler; chop $ruler; # Remove the trailing spaces
+
+    if ( length $ruler > MAX_RULER_CONTENT ) {
+	substr $ruler, RULER_CONTENT_TRIM, length TRIM_MARK, TRIM_MARK;
+    }
+    $ruler = LEADER . $ruler . TRAILER;
+    $ruler .= '=' x ( WIDTH - length( $ruler ) );
+    $formatter->_output( "\r$ruler");
 }
 
 =head3 C<result>
@@ -121,16 +146,7 @@ sub result {
             return $self->SUPER::result( $result );
         }
 
-        my $ceiling = $context->{tests} / 5;
-
-        # Find the next highest power of two, in linear time.
-        my $binary = unpack "B*", pack "N", $ceiling;
-        $binary =~ s/^0+//;
-        my $test_print_modulus = 1 << length $binary;
-
-        unless ( $context->{tests} % $test_print_modulus ) {
-            $self->_output_ruler;
-        }
+	$self->_output_ruler( $self->parser->tests_run == 1 );
     }
     elsif ( $result->is_bailout ) {
         $formatter->_failure_output(
@@ -180,7 +196,7 @@ sub close_test {
     $self->_need_refresh;
 
     if (@$active > 1) {
-        $self->_output_ruler;
+        $self->_output_ruler( 2 );
     } elsif (@$active < 1) {
         # $self->formatter->_output("\n");
         delete $shared{$formatter};



More information about the tapx-dev mailing list