This repository has been archived by the owner on Jun 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalltests.pl
executable file
·102 lines (75 loc) · 1.96 KB
/
alltests.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/perl
# Run all Deck regression tests and compare their results with
# expected results.
use strict;
use warnings;
use File::Basename;
use File::Temp qq{tempfile};
{
chdir("tests") or die "Unable to chdir to 'tests'\n";
my $upto = shift || "";
$upto = basename($upto) if $upto;
die "No test named '$upto'\n" unless !$upto || -f $upto;
my @tests = glob('test*.dk');
my @failures = glob('fail*.dk');
my @sh = glob('*.sh');
for my $test (@tests, @sh, @failures) {
if ($upto) {
next unless $upto eq $test;
$upto = "";
}
if ($upto) {
print "Skipping $test\n";
next;
}
runtest($test);
}
}
sub runtest {
my ($file) = @_;
doRun($file);
doRun($file, 1) if $file =~ /^fail/;
}
sub doRun {
my ($file, $bt) = @_;
my $cmd = '../udeck.pl --flush' . ($bt ? " --backtrace" : "");
$cmd = "bash" if $file =~ /\.sh$/;
# Test if we're expecting failure
my $fail = ($cmd =~ /^fail/);
# Compute the result file name
my $resultFileName = $file;
$resultFileName =~ s/\.(dk|sh)$//;
$resultFileName .= ".bt" if $bt;
$resultFileName .= ".txt";
# And skip if the file is missing
if (! -f $resultFileName) {
print "Skipping $file: No results file.\n" unless $bt;
return;
}
print "$file", ($bt) ? " (backtrace)" : "", "\n";
# Run the test and exit if it did not exit in the expected way
my $result = `$cmd $file 2>&1`;
if ($? >> 16) {
die "$file failed unexpectedly.\n" unless $fail;
} else {
die "$file succeeded unexpectedly.\n" if $fail;
}
# Compare the results. If different, run diff on them
my $expected = slurp($resultFileName);
return if $expected eq $result;
my ($fh, $filename) = tempfile();
print {$fh} $result;
close ($fh);
print `diff $filename $resultFileName`;
unlink($filename);
exit(1);
}
sub slurp {
my ($filename) = @_;
local $/ = undef;
open my $fh, "<$filename"
or die "Unable to open '$filename' for reading.\n";
my $result = <$fh>;
close ($fh);
return $result;
}