]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/commitdiff
wvtestrun produces nicer and more readable output
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sat, 12 Mar 2011 14:40:43 +0000 (15:40 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Sat, 12 Mar 2011 16:09:31 +0000 (17:09 +0100)
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.

src/wvtest/wvtestrun

index 0bd917fb1a0dda76068268ebe46c4d6a381b0c20..fd15b084d7e18b4a2930f4e63d2fbf18238bfdd7 100755 (executable)
@@ -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