-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.pl
40 lines (33 loc) · 1005 Bytes
/
test.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
if ($ARGV[0]) {
$prog=$ARGV[0];
} else {
$prog="./retry" ;
}
if (! -x "$prog") {
die("$prog is non-existent or not executable: please define the path or compile first");
}
sub runtest {
my $testname=shift @_;
my $expectrt=shift @_;
my $cmd=$prog." ".join(' ',@_);
my $out=`$cmd 2>&1`;
my $rt=${^CHILD_ERROR_NATIVE};
if ($rt!=$expectrt) {
die "$testname failed with ".$rt.": $!";
}
return $out;
}
my $d=`dirname $0`;
chomp $d;
chdir("$d");
runtest("Failed args",256,"1","0");
runtest("Basic test always fail",256,"1","0","/bin/false");
runtest("Basic test always success",0,"1","0","/bin/true");
runtest("Basic test sometimes fail",0,"5","1","perl","./testretry.pl");
my $output=runtest("Some output",0,"5","1","perl","./testretry.pl","HUUHAA");
sleep(1);
$output.=runtest("Some output",0,"5","1","perl","./testretry.pl","HUUHAA");
if ("$output" ne "HUUHAA\nSTDERR: HUUHAA\nHUUHAA\nSTDERR: HUUHAA\n") {
die("Output test failed with $output\n");
}
print "$0: All tests passed ok\n";