From: Michal Sojka Date: Sat, 12 Mar 2011 14:40:43 +0000 (+0100) Subject: wvtestrun produces nicer and more readable output X-Git-Url: https://rtime.felk.cvut.cz/gitweb/frescor/frsh-forb.git/commitdiff_plain/b8649e4affa087dbf9979805a6a24db8adde054a wvtestrun produces nicer and more readable output Now, when stdout is a TTY, the results are aligned to the same column and are preceeded by colorized leaders ("........") to easily find the text matching to the result. --- diff --git a/src/wvtest/wvtestrun b/src/wvtest/wvtestrun index 0bd917fb..fd15b084 100755 --- a/src/wvtest/wvtestrun +++ b/src/wvtest/wvtestrun @@ -28,8 +28,11 @@ if (!$pid) { } my $istty = -t STDOUT && $ENV{'TERM'} ne "dumb"; +my $columns = `tput cols` if ($istty); + my @log = (); my ($gpasses, $gfails) = (0,0); +my $column = 0; sub bigkill($) { @@ -63,17 +66,17 @@ local $SIG{ALRM} = sub { bigkill($pid); }; -my $column = `tput cols` - 10; - -sub colourize($) +sub colourize($$) { - my $result = shift; + my ($column, $result) = @_; my $pass = ($result eq "ok"); - + if ($istty) { + my $dots = $columns - 15 - $column%$columns; + $dots += $columns if ($dots < 0); + my $leader = "."x$dots; my $colour = $pass ? "\e[32;1m" : "\e[31;1m"; - my $column = "\e[${column}G"; - return "$column$colour$result\e[0m"; + return "$colour$leader $result\e[0m"; } else { return $result; } @@ -86,18 +89,18 @@ sub mstime($$$) my $str = sprintf("%d.%03ds", $ms/1000, $ms % 1000); if ($istty && $ms > $badtime) { - return "\e[31;1m$str\e[0m"; + return ("\e[31;1m$str\e[0m", length($str)); } elsif ($istty && $ms > $warntime) { - return "\e[33;1m$str\e[0m"; + return ("\e[33;1m$str\e[0m", length($str)); } else { - return "$str"; + return ("$str", length($str)); } } sub resultline($$) { my ($name, $result) = @_; - return sprintf("! %-65s %s", $name, colourize($result)); + return sprintf("! %s %s", $name, colourize(2+length($name)+1, $result)); } my $allstart = time(); @@ -107,7 +110,8 @@ sub endsect() { $stop = time(); if ($start) { - printf " %s %s\n", mstime($stop - $start, 500, 1000), colourize("ok"); + my ($time, $timelength) = mstime($stop - $start, 500, 1000); + printf " %s %s\n", $time, colourize($column + 2 + $timelength, "ok"); } } @@ -123,7 +127,9 @@ while (<$fh>) endsect(); - printf("! %s %s: ", $file, $sect); + my $msg = sprintf("! %s %s: ", $file, $sect); + print $msg; + $column = length($msg); @log = (); push @log, "-"x78; $start = $stop; @@ -137,6 +143,7 @@ while (<$fh>) if (!$start) { printf("\n! Startup: "); + $column = 11; $start = time(); } @@ -151,6 +158,7 @@ while (<$fh>) } else { $gpasses++; print "."; + $column++; } } else