Browse Source

Another familiar, this one would jump on my shoulder until I fix it.

Alois Mahdal 12 years ago
parent
commit
fb625497d1
1 changed files with 99 additions and 0 deletions
  1. 99
    0
      bin/autotest.pl

+ 99
- 0
bin/autotest.pl View File

@@ -0,0 +1,99 @@
1
+#!/usr/bin/perl -w
2
+
3
+## Author: Alois Mahdal at zxcvb cz
4
+# my private testing helper script
5
+
6
+# This program is free software: you can redistribute it and/or modify
7
+# it under the terms of the GNU General Public License as published by
8
+# the Free Software Foundation, either version 3 of the License, or
9
+# (at your option) any later version.
10
+
11
+# This program is distributed in the hope that it will be useful,
12
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+# GNU General Public License for more details.
15
+
16
+# You should have received a copy of the GNU General Public License
17
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
+
19
+
20
+use v5.10;
21
+use warnings;
22
+
23
+$PLATFORM   = (-d "c:\\windows" ? 'windows' : 'unix' );
24
+$DUMPS      = "dumps";
25
+$TESTS      = "t";
26
+$COLORS     = { windows => { ok => 'color 0a', nok => 'color 0c' } };
27
+
28
+sub clear {
29
+    if ($PLATFORM eq 'windows') {
30
+        system "cls";
31
+    } elsif ($PLATFORM eq 'unix') {
32
+        system "clear";
33
+    }
34
+}
35
+
36
+sub color {
37
+	$mood = shift;
38
+	$cmd = $COLORS->{$PLATFORM}->{$mood};
39
+	system ($cmd) if $cmd;
40
+}
41
+
42
+sub cat {
43
+	$_  = shift;
44
+    my ($name) = m|^.*/(.*?)$|;
45
+    printf "$name:\n";
46
+    if (open my $fh,  "<", $_) {
47
+        my @lines = <$fh>;
48
+        print @lines, "\n";
49
+        close $fh or die "cannot close $_"
50
+    }
51
+    else {
52
+        warn "cannot open $_";
53
+        next STDERR;
54
+    }
55
+}
56
+
57
+sub run_tests {
58
+    my $ret = 0;
59
+	printf "===== STDOUT =====\n";
60
+	foreach (@_) {
61
+        s|^$TESTS/*||;
62
+        say "$_:"; 
63
+		$cmd = sprintf 'perl %s 2>%s', "$TESTS\\$_", "$DUMPS\\$_.err";
64
+		system($cmd);
65
+		$ret = $? >> 8;
66
+        if ($ret) {
67
+            print "last test failed with exit code $ret!\n";
68
+            return;
69
+        }
70
+	}
71
+	return 1;
72
+}
73
+
74
+sub freakout {
75
+    my $ret = shift;
76
+	color "nok";
77
+	my @paths = glob "$DUMPS/*.err";
78
+	printf "\n===== STDERR =====\n";
79
+    STDERR: foreach (@paths) {
80
+        cat $_ and unlink $_ or warn "could not print $_";
81
+    }
82
+}
83
+
84
+mkdir $DUMPS unless -d $DUMPS;
85
+
86
+while (1) {
87
+	my @paths = glob "$TESTS/*.t";
88
+	&clear;
89
+	color "ok";
90
+    my $ok = &run_tests(@paths);
91
+    if ($ok) {
92
+        say "------------------";
93
+        say "All tests finished.";
94
+    } else {
95
+        &freakout();
96
+    }
97
+	sleep 5;
98
+}
99
+