/
testall.pl
executable file
·105 lines (86 loc) · 4.2 KB
/
testall.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
103
104
105
#!/usr/bin/perl
use warnings;
use strict;
use Term::ANSIColor;
use File::Compare;
# root dir of all tests
my $root = '.';
my $compiler = '../cc1';
#counters
my $testPass = 0;
my $totalTest = 0;
#diff command
my $command = "sdiff";
#Open root dir
opendir(D, $root) || die "Can't open directory: $!\n";
while (my $f = readdir(D)) {
if ( -d $f ){
if ( $f ne "." && $f ne ".." && $f ne ".git"){
# For each directory iterate through all test cases and compare output storing results
opendir(TESTDIR, "$root/$f");
#print title report
print colored( "**********************************************************************************", 'BLACK ON_WHITE' ), "\r\n";
print colored( "********** **********", 'BLACK ON_WHITE' ), "\r\n";
print colored( sprintf("**************** Running %-40s ****************", "$f Tests"), 'BLACK ON_WHITE' ), "\n";
print colored( "********** **********", 'BLACK ON_WHITE' ), "\r\n";
print colored( "**********************************************************************************", 'BLACK ON_WHITE' ), "\r\n";
#clean up assembly files
`rm -f $root/$f/*.s`;
#iterate through each test file
while (my $testfile = readdir(TESTDIR)){
if (!-d $testfile && $testfile ne "answers"){ # hack to ignore answer folder cause somehow the -d is not working right....
#run each test case
`$compiler "$f/$testfile" 2>/dev/null`;
#clean up assembly files
`rm -f $root/$f/*.s`;
if($? != 0){
print colored( sprintf("%-40sCRASH FAIL", $testfile), 'BLACK ON_RED' ), "\n";
}
else{
my $answerFileName = substr($testfile, 0, -2) . ".txt";
my $diffResults = `$command ./output.txt ./$f/answers/$answerFileName -s -W`;
if($? != 0){
print colored( sprintf("%-40sFAIL", $testfile), 'red' ), "\n";
}
elsif (length($diffResults) != 0) {
print colored( sprintf("%-40s", $testfile), 'bright_blue' );
print colored("FAIL", "red"), "\n";
}
else{
print colored( sprintf("%-40s", $testfile), 'bright_blue' );
print colored("PASS", "green"), "\n";
$testPass++;
}
}
$totalTest++;
}
}
print "\n\n";
closedir(TESTDIR);
}
}
}
closedir(D);
#print final test results
if($totalTest == $testPass){
print colored(' /$$$$$$ /$$ /$$ /$$$$$$ /$$$$$$ /$$$$$$$$ /$$$$$$ /$$', 'green'), "\n";
print colored(' /$$__ $$| $$ | $$ /$$__ $$ /$$__ $$| $$_____/ /$$__ $$| $$', 'green'), "\n";
print colored('| $$ \__/| $$ | $$| $$ \__/| $$ \__/| $$ | $$ \__/| $$', 'green'), "\n";
print colored('| $$$$$$ | $$ | $$| $$ | $$ | $$$$$ | $$$$$$ | $$', 'green'), "\n";
print colored(' \____ $$| $$ | $$| $$ | $$ | $$__/ \____ $$|__/', 'green'), "\n";
print colored(' /$$ \ $$| $$ | $$| $$ $$| $$ $$| $$ /$$ \ $$ ', 'green'), "\n";
print colored('| $$$$$$/| $$$$$$/| $$$$$$/| $$$$$$/| $$$$$$$$| $$$$$$/ /$$', 'green'), "\n";
print colored(' \______/ \______/ \______/ \______/ |________/ \______/ |__/', 'green'), "\n\n";
print colored("Passed: $testPass / $totalTest", 'green') , "\n\n\n";
}
else{
print colored(' ( ( ( ( ( ', 'YELLOW'), "\n";
print colored(' * ) )\ ) * ) )\ ) ( )\ ) )\ ) )\ ) ', 'YELLOW'), "\n";
print colored('` ) /( ( (()/(` ) /( (()/( )\ (()/((()/( ( (()/( ', 'YELLOW'), "\n";
print colored(' ( )(_)))\ /(_))( )(_)) /(_))((((_)( /(_))/(_)) )\ /(_)) ', 'YELLOW'), "\n";
print colored('(_(_())((_) (_)) (_(_()) (_))_| )\ _ )\ (_)) (_)) ((_)(_))_ ', 'YELLOW'), "\n";
print colored('|_ _|| __|/ __||_ _| | |_ (_)_\(_)|_ _|| | | __|| \ ', 'red'), "\n";
print colored(' | | | _| \__ \ | | | __| / _ \ | | | |__ | _| | |) | ', 'red'), "\n";
print colored(' |_| |___||___/ |_| |_| /_/ \_\ |___||____||___||___/ ', 'red'), "\n\n";
print colored("Passed: $testPass / $totalTest", 'red') , "\n\n\n";
}