-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.pl
executable file
·76 lines (66 loc) · 1.74 KB
/
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
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
#!/usr/bin/perl
use strict;
use Getopt::Long;
use Time::HiRes;
my $interactive=1; # run kdiff3
my $continue=0;
GetOptions(
'i|interactive!'=> \$interactive,
'c|continue!' => \$continue,
) or die;
my $TESTDATA_DIR = 'testdata';
my $TEST_TEMP_DIR = '/tmp/ort-test';
`rm -rf $TEST_TEMP_DIR/`;
`mkdir $TEST_TEMP_DIR`;
my $start_time=Time::HiRes::time;
my $successful=0;
my $failed=0;
for (my $i=$ARGV[0] || 0 ; ; ++$i) {
my $test_input = "$TESTDATA_DIR/in${i}.txt";
my $test_output = "$TEST_TEMP_DIR/out${i}.txt";
my $test_expected = "$TESTDATA_DIR/out${i}.txt";
my $test_params = "$TESTDATA_DIR/param${i}.txt";
last unless(-e $test_input && -e $test_expected);
my $params = read_params($test_params);
print '.';
system("./text.pl $params $test_input $test_output") == 0 or die "Died on test $i";
my $equal = &compare_files($test_output, $test_expected);
if (!$equal) {
print "Test no. $i failed.\n";
my $diff_program = $interactive && `which kdiff3` ? 'kdiff3' : 'diff --unified=2';
system("$diff_program $test_output $test_expected");
exit(11) unless $continue;
++$failed;
} else {
++$successful;
}
}
print "\n$successful tests succeeded";
if ($failed) {
print " $failed failed";
}
printf(" in %.2f ms\n", Time::HiRes::time - $start_time);
exit($failed ? 11 : 0);
# returns true if files are identical, otherwise false.
# when files are not identical, prints diff to standard output.
sub compare_files {
my ($file1,$file2) = @_;
my $result = `diff $file1 $file2`;
if ($result eq '') {
return 1;
} else {
#print $result;
return 0;
}
}
sub read_params {
my ($file) = @_;
my $params = '';
if (-e $file) {
open(PARFILE, $file) or die "cannot read $file";
$params = <PARFILE>;
chomp $params;
close(PARFILE);
}
return $params;
}