Ok - I think this has all of the bits working necessary to compile WvStreams
[wvstreams.git] / wvtestrunner.pl
blobe210c76827f5f8a44430eab9fcdbff0a55fbb4dd
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 "\n! Killed by signal FAILED\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 { bigkill($pid); };
54 local $SIG{ALRM} = sub {
55 print STDERR "Alarm timed out! No test results for too long.\n";
56 bigkill($pid);
59 sub colourize($)
61 my $result = shift;
62 my $pass = ($result eq "ok");
64 if ($istty) {
65 my $colour = $pass ? "\e[32;1m" : "\e[31;1m";
66 return "$colour$result\e[0m";
67 } else {
68 return $result;
72 sub resultline($$)
74 my ($name, $result) = @_;
75 return sprintf("! %-65s %s", $name, colourize($result));
78 my $insection = 0;
80 while (<$fh>)
82 chomp;
83 s/\r//g;
85 if (/^\s*Testing "(.*)" in (.*):\s*$/)
87 alarm(120);
89 my ($sect, $file) = ($1, $2);
91 if ($insection) {
92 printf " %s\n", colourize("ok");
95 printf("! %s %s: ", $file, $sect);
96 @log = ();
97 $insection = 1;
99 elsif (/^!\s*(.*?)\s+(\S+)\s*$/)
101 alarm(120);
103 my ($name, $result) = ($1, $2);
104 my $pass = ($result eq "ok");
106 if (!$insection) {
107 printf("\n! Startup: ");
109 $insection++;
111 push @log, resultline($name, $result);
113 if (!$pass) {
114 $gfails++;
115 if (@log) {
116 print "\n" . join("\n", @log) . "\n";
117 @log = ();
119 } else {
120 $gpasses++;
121 print ".";
124 else
126 push @log, $_;
130 if ($insection) {
131 printf " %s\n", colourize("ok");
134 my $newpid = waitpid($pid, 0);
135 if ($newpid != $pid) {
136 die("waitpid returned '$newpid', expected '$pid'\n");
139 my $code = $?;
140 my $ret = ($code >> 8);
142 # return death-from-signal exits as >128. This is what bash does if you ran
143 # the program directly.
144 if ($code && !$ret) { $ret = $code | 128; }
146 if ($ret && @log) {
147 print "\n" . join("\n", @log) . "\n";
150 if ($code != 0) {
151 print resultline("Program returned non-zero exit code ($ret)", "FAILED");
154 my $gtotal = $gpasses+$gfails;
155 printf("\nWvTest: %d test%s, %d failure%s.\n",
156 $gtotal, $gtotal==1 ? "" : "s",
157 $gfails, $gfails==1 ? "" : "s");
158 print STDERR "\nWvTest result code: $ret\n";
159 exit( $ret ? $ret : ($gfails ? 125 : 0) );