Replaced wvtesthelper/meter/colour scripts with an all-new wvtestrunner.pl.
[wvstreams.git] / wvtestrunner.pl
blob9eace827ed74209d15a6caee7446c6554cb48e9d
1 #!/usr/bin/perl -w
2 use strict;
4 # always flush
5 $| = 1;
7 if (@ARGV < 1) {
8 print STDERR "Usage: $0 <command line...>\n";
9 exit 127;
12 print STDERR "Testing \"all\" in @ARGV:\n";
14 my $pid = open(my $fh, "-|");
15 if (!$pid) {
16 # child
17 setpgrp();
18 open STDERR, '>&STDOUT' or die("Can't dup stdout: $!\n");
19 exec(@ARGV);
20 exit 126; # just in case
23 my $istty = -t STDOUT;
24 my @log = ();
25 my ($gpasses, $gfails) = (0,0);
27 sub bigkill($)
29 my $pid = shift;
31 if (@log) {
32 print "\n" . join("\n", @log) . "\n";
35 print STDERR "Killed by signal.\n";
37 ($pid > 0) || die("pid is '$pid'?!\n");
39 local $SIG{CHLD} = sub { }; # this will wake us from sleep() faster
40 kill 15, $pid;
41 sleep(2);
43 if ($pid > 1) {
44 kill 9, -$pid;
46 kill 9, $pid;
48 exit(125);
51 # parent
52 local $SIG{INT} = sub { bigkill($pid); };
53 local $SIG{TERM} = sub { bikill($pid); };
55 sub colourize($)
57 my $result = shift;
58 my $pass = ($result eq "ok");
60 if ($istty) {
61 my $colour = $pass ? "\e[32;1m" : "\e[31;1m";
62 return "$colour$result\e[0m";
63 } else {
64 return $result;
68 sub resultline($$)
70 my ($name, $result) = @_;
71 return sprintf("! %-65s %s", $name, colourize($result));
74 my $insection = 0;
76 while (<$fh>)
78 chomp;
80 if (/^\s*Testing "(.*)" in (.*):\s*$/)
82 my ($sect, $file) = ($1, $2);
84 if ($insection) {
85 printf " %s\n", colourize("ok");
88 printf("! %s %s: ", $file, $sect);
89 @log = ();
90 $insection = 1;
92 elsif (/^!\s*(.*?)\s+(\S+)\s*$/)
94 my ($name, $result) = ($1, $2);
95 my $pass = ($result eq "ok");
97 if (!$insection) {
98 printf("\n! Startup: ");
100 $insection++;
102 push @log, resultline($name, $result);
104 if (!$pass) {
105 $gfails++;
106 if (@log) {
107 print "\n" . join("\n", @log) . "\n";
108 @log = ();
110 } else {
111 $gpasses++;
112 print ".";
115 else
117 push @log, $_;
121 if ($insection) {
122 printf " %s\n", colourize("ok");
125 my $newpid = waitpid($pid, 0);
126 if ($newpid != $pid) {
127 die("waitpid returned '$newpid', expected '$pid'\n");
130 my $code = $?;
131 my $ret = ($code >> 8);
133 if ($ret && @log) {
134 print "\n" . join("\n", @log) . "\n";
138 my $gtotal = $gpasses+$gfails;
139 printf("\nWvTest: %d test%s, %d failure%s.\n",
140 $gtotal, $gtotal==1 ? "" : "s",
141 $gfails, $gfails==1 ? "" : "s");
142 print STDERR "\nWvTest result code: $ret\n";
143 exit( $ret ? $ret : ($gfails ? 125 : 0) );