diff options
Diffstat (limited to 'test')
-rwxr-xr-x | test/run | 58 |
1 files changed, 50 insertions, 8 deletions
@@ -40,12 +40,12 @@ use strict; use FileHandle; use Getopt::Std; use POSIX qw(isatty setuid getcwd); -use vars qw($opt_l $opt_v); +use vars qw($opt_l $opt_q $opt_v %output); no warnings qw(taint); $opt_l = ~0; # a really huge number -getopts('l:v'); +getopts('l:qv'); my ($OK, $FAILED) = ("ok", "failed"); if (isatty(fileno(STDOUT))) { @@ -55,6 +55,10 @@ if (isatty(fileno(STDOUT))) { sub exec_test($$); sub process_test($$$$); +sub print_header($); +sub print_body($); +sub print_footer($); +sub flush_output($); my ($prog, $in, $out) = ([], [], []); my $prog_line = 0; @@ -71,6 +75,7 @@ $ENV{PWD} = getcwd; if (defined $ARGV[0]) { open(SOURCE, "$origdir/$ARGV[0]"); + print_header "[$ARGV[0]]\n"; } else { *SOURCE = *STDIN; } @@ -121,7 +126,8 @@ if (isatty(fileno(STDOUT))) { $status = "\033[32m" . $status . "\033[m"; } } -print $status, "\n"; +print_footer "$status\n"; +flush_output $failed; exit $failed ? 1 : 0; @@ -131,8 +137,8 @@ sub process_test($$$$) { return unless @$prog; my $p = [ @$prog ]; - print "[$prog_line] \$ ", join(' ', - map { s/\s/\\$&/g; $_ } @$p), " -- "; + print_body "[$prog_line] \$ ".join(' ', + map { s/\s/\\$&/g; $_ } @$p)." -- "; my $result = exec_test($prog, $in); my @good = (); my $nmax = (@$out > @$result) ? @$out : @$result; @@ -155,15 +161,15 @@ sub process_test($$$$) { my $good = !(grep /!/, @good); $tests++; $failed++ unless $good; - print $good ? $OK : $FAILED, "\n"; + print_body(($good ? $OK : $FAILED)."\n"); if (!$good || $opt_v) { for (my $n=0; $n < $nmax; $n++) { my $l = defined($out->[$n]) ? $out->[$n] : "~"; chomp $l; my $r = defined($result->[$n]) ? $result->[$n] : "~"; chomp $r; - print sprintf("%-" . ($width-3) . "s %s %s\n", - $r, $good[$n], $l); + print_body sprintf("%-" . ($width-3) . "s %s %s\n", + $r, $good[$n], $l); } } } @@ -341,3 +347,39 @@ sub exec_test($$) { } } +sub print_header($) +{ + if ($opt_q) { + $output{header} = $_[0]; + } else { + print $_[0]; + } +} + +sub print_body($) +{ + if ($opt_q) { + $output{body} .= $_[0]; + } else { + print $_[0]; + } +} + +sub print_footer($) +{ + if ($opt_q) { + $output{footer} .= $_[0]; + } else { + print $_[0]; + } +} + +sub flush_output($) +{ + my $failed = shift; + return unless $opt_q; + + print $output{header} || "", + $failed ? $output{body} : "", + $output{footer} || ""; +} |