-
Notifications
You must be signed in to change notification settings - Fork 13
/
tests.pl
executable file
·64 lines (51 loc) · 1.47 KB
/
tests.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
#!/usr/bin/perl
use strict;
use File::Temp qw(tempfile);
$ENV{PATH} = '/home/ubuntu/bin:' . $ENV{PATH};
sub which {
my ($filename) = @_;
my $result = `which $filename`;
chomp $result;
die "$filename not found\n" unless $result;
$result;
}
my @run_tests = grep(!/root/, split(/\s+/, `ls *.t`));
my @command_tests = (
['./arc-script-test.pl'],
['sudo', which('mzscheme'), 'run', 'io-root.t'],
['sudo', which('racket'), 'run', 'io-root.t']
);
my @tests = @command_tests;
for my $run_test (@run_tests) {
# Running the same test file simultaneously is broken because
# tests use the same temp files and directories.
push @tests, ['mzscheme', 'run', $run_test];
push @tests, ['racket', 'run', $run_test];
}
my $children = {};
print "testing...\n";
for my $test (@tests) {
my ($fh, $filename) = tempfile();
close $fh;
my $pid = fork();
die "can't fork\n" unless defined $pid;
if ($pid == 0) {
open(STDOUT, '>', $filename);
open(STDERR, '>&STDOUT');
exec(@$test) or die "exec: $!\n";
}
$children->{$pid} = [$test, $filename];
}
$| = 1;
while ((my $pid = wait()) != -1) {
my $child = $children->{$pid};
next unless defined $child;
if ($? != 0) {
system('cat', $child->[1]);
print "failed: ", join(' ', @{$child->[0]}), "\n";
kill 'INT', keys(%$children);
last;
}
print "ok: ", join(' ', @{$child->[0]}), "\n";
delete $children->{$pid};
}