4 # Copyright (C)2007-2009 Versabanq Innovations Inc. and contributors.
5 # Licensed under the GNU Library General Public License, version 2.
6 # See the included file named LICENSE for license information.
12 print STDERR "Usage: $0 [-vs] <file>\n";
16 my ($verbose, $summary, $limit_lines);
19 "verbose|v" => \$verbose,
20 "summary|s" => \$summary,
21 "before-failure|b=i" => \$limit_lines,
24 my $istty = -t STDOUT && $ENV{'TERM'} ne "dumb";
27 $columns = `tput cols`;
29 $columns = $ENV{'COLUMNS'} || 80;
34 my ($gpasses, $gfails) = (0,0);
35 my ($lpasses, $lfails) = (0,0);
36 my ($tpasses, $tfails) = (0,0);
40 my ($column, $result) = @_;
41 my $pass = ($result eq "ok");
43 my $begcolour = $istty ? ($pass ? "\e[32;1m" : "\e[31;1m") : "";
44 my $endcolour = $istty ? "\e[0m" : "";
46 my $dots = $columns - 15 - $column%$columns;
47 $dots += $columns if ($dots < 0);
48 my $leader = "."x$dots;
49 return "$begcolour$leader $result$endcolour";
55 my $begcolour = $istty ? "\e[1m\e[4m" : "";
56 my $endcolour = $istty ? "\e[0m" : "";
57 return "$begcolour$msg$endcolour";
62 my ($prefix, $name, $result) = @_;
63 if (!defined $prefix) { $prefix = ''; }
64 return sprintf("$prefix! %s %s", $name, colourize(length($prefix)+2+length($name)+1, $result));
67 sub print_and_clear_log()
69 print "v"x($columns-1) . "\n"; # Top marker
73 if (/^(\([0-9]+\) (# )?)?!\s*(.*?)\s+(\S+)\s*$/) {
74 my ($prefix, $name, $result) = ($1, $3, $4);
75 push @log2print, resultline($prefix, $name, $result);
76 if ($result ne "ok") {
77 print "wvformat: skipped $skipped lines\n" if $skipped;
78 print join("\n", @log2print) . "\n";
85 while (defined $limit_lines && scalar(@log2print) > $limit_lines) {
90 print "wvformat: skipped $skipped lines\n" if $skipped;
91 print join("\n", @log2print) . "\n";
92 print "^"x($columns-1) . "\n"; # Bottom marker
96 sub print_test_summary()
99 print(resultline("", sprintf("%s %s [%d/%d]", $file, $sect, $lpasses, $lpasses+$lfails),
100 $lfails ? "FAILED" : "ok") . "\n");
101 print_and_clear_log() if ($lfails && !$summary);
103 if ($lfails) { $tfails++; }
105 ($lpasses, $lfails) = (0,0);
115 if (/^(\([0-9]+\) )?\s*Testing "(.*)" in (.*):\s*$/)
117 print_test_summary() unless $startup;
119 (undef, $sect, $file) = ($1, $2, $3);
122 print highlight($_), "\n";
125 elsif (/^(\([0-9]+\) (# )?)?!\s*(.*?)\s+(\S+)\s*$/)
127 my ($prefix, $name, $result) = ($1, $3, $4);
136 print resultline($prefix, $name, $result) . "\n";
141 if ($result eq "ok") {
160 print_test_summary();
162 print_and_clear_log();
166 my $gtotal = $gpasses+$gfails;
167 my $ttotal = $tpasses+$tfails;
168 printf("\nSummary: %d test%s, %d failure%s".
169 "\n %d check%s, %d failure%s\n",
170 $ttotal, $ttotal==1 ? "" : "s",
171 $tfails, $tfails==1 ? "" : "s",
172 $gtotal, $gtotal==1 ? "" : "s",
173 $gfails, $gfails==1 ? "" : "s");