author | Ethan Lee <flibitijibibo@flibitijibibo.com> |
Sun, 30 Aug 2020 21:35:31 -0400 | |
changeset 1303 | 7a43f238f28a |
parent 889 | d3ecff60a3f5 |
permissions | -rwxr-xr-x |
736
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 |
#!/usr/bin/perl -w |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 |
|
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 |
use warnings; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 |
use strict; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 |
use Digest::SHA1; |
876
e005b1f38952
Changed where we spawn mojoshader-compiler from, for __FILE__ testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
750
diff
changeset
|
6 |
use Cwd; |
736
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 |
|
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 |
use FindBin qw($Bin); |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 |
my $testdir = $Bin; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 |
undef $Bin; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
11 |
#print("testdir is $testdir\n"); |
876
e005b1f38952
Changed where we spawn mojoshader-compiler from, for __FILE__ testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
750
diff
changeset
|
12 |
my $binpath = getcwd(); |
e005b1f38952
Changed where we spawn mojoshader-compiler from, for __FILE__ testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
750
diff
changeset
|
13 |
#print("binpath is $binpath\n"); |
742
2108031e4ef5
Fixed command lines for unit tests.
Ryan C. Gordon <icculus@icculus.org>
parents:
741
diff
changeset
|
14 |
|
2108031e4ef5
Fixed command lines for unit tests.
Ryan C. Gordon <icculus@icculus.org>
parents:
741
diff
changeset
|
15 |
my $GPrintCmds = 0; |
2108031e4ef5
Fixed command lines for unit tests.
Ryan C. Gordon <icculus@icculus.org>
parents:
741
diff
changeset
|
16 |
|
740
13c0707a2e3f
Minor cleanup; crunch down list to one line.
Ryan C. Gordon <icculus@icculus.org>
parents:
736
diff
changeset
|
17 |
my @modules = qw( preprocessor assembler compiler parser ); |
736
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
18 |
|
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
19 |
|
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
20 |
sub compare_files { |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
21 |
my ($a, $b, $endlines) = @_; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
22 |
|
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
23 |
if (not open(FILE1, '<', $a)) { |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
24 |
return (0, "Couldn't open '$a' for checksum"); |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
25 |
} |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
26 |
if (not open(FILE2, '<', $b)) { |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
27 |
close(FILE1); |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
28 |
return (0, "Couldn't open '$b' for checksum"); |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
29 |
} |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
30 |
|
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
31 |
my $sha1 = Digest::SHA1->new; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
32 |
my $sha2 = Digest::SHA1->new; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
33 |
|
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 |
if (not $endlines) { |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 |
$sha1->addfile(*FILE1); |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
36 |
$sha2->addfile(*FILE2); |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
37 |
} else { |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
38 |
while (<FILE1>) { s/[\r\n]//g; $sha1->add($_); } |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
39 |
while (<FILE2>) { s/[\r\n]//g; $sha2->add($_); } |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 |
} |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
41 |
|
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 |
close(FILE1); |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
43 |
close(FILE2); |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
44 |
|
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
45 |
if ($sha1->hexdigest ne $sha2->hexdigest) { |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 |
return (0, "Result doesn't match expectations"); |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
47 |
} |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
48 |
|
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
49 |
return (1); |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 |
} |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
51 |
|
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
52 |
my %tests = (); |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
53 |
|
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
54 |
$tests{'output'} = sub { |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
55 |
my ($module, $fname) = @_; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
56 |
my $output = 'unittest_tempoutput'; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
57 |
my $desired = $fname . '.correct'; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
58 |
my $cmd = undef; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
59 |
my $endlines = 1; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 |
|
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 |
# !!! FIXME: this should go elsewhere. |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
62 |
if ($module eq 'preprocessor') { |
876
e005b1f38952
Changed where we spawn mojoshader-compiler from, for __FILE__ testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
750
diff
changeset
|
63 |
$cmd = "$binpath/mojoshader-compiler -P '$fname' -o '$output'"; |
736
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
64 |
} else { |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
65 |
return (0, "Don't know how to do this module type"); |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 |
} |
742
2108031e4ef5
Fixed command lines for unit tests.
Ryan C. Gordon <icculus@icculus.org>
parents:
741
diff
changeset
|
67 |
$cmd .= ' 2>/dev/null 1>/dev/null'; |
2108031e4ef5
Fixed command lines for unit tests.
Ryan C. Gordon <icculus@icculus.org>
parents:
741
diff
changeset
|
68 |
|
2108031e4ef5
Fixed command lines for unit tests.
Ryan C. Gordon <icculus@icculus.org>
parents:
741
diff
changeset
|
69 |
print("$cmd\n") if ($GPrintCmds); |
736
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
70 |
|
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 |
if (system($cmd) != 0) { |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 |
unlink($output) if (-f $output); |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
73 |
return (0, "External program reported error"); |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
74 |
} |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
75 |
|
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
76 |
if (not -f $output) { return (0, "Didn't get any output file"); } |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
77 |
|
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
78 |
my @retval = compare_files($desired, $output, $endlines); |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
79 |
unlink($output); |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
80 |
return @retval; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
81 |
}; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
82 |
|
750
238675cfa788
Added unit test framework stub for error testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
742
diff
changeset
|
83 |
$tests{'errors'} = sub { |
885
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
84 |
my ($module, $fname) = @_; |
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
85 |
my $error_output = 'unittest_temperroutput'; |
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
86 |
my $output = 'unittest_tempoutput'; |
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
87 |
my $desired = $fname . '.correct'; |
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
88 |
my $cmd = undef; |
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
89 |
my $endlines = 1; |
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
90 |
|
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
91 |
# !!! FIXME: this should go elsewhere. |
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
92 |
if ($module eq 'preprocessor') { |
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
93 |
$cmd = "$binpath/mojoshader-compiler -P '$fname' -o '$output'"; |
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
94 |
} else { |
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
95 |
return (0, "Don't know how to do this module type"); |
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
96 |
} |
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
97 |
$cmd .= " 2>$error_output 1>/dev/null"; |
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
98 |
|
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
99 |
print("$cmd\n") if ($GPrintCmds); |
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
100 |
|
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
101 |
system($cmd); |
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
102 |
unlink($output) if (-f $output); |
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
103 |
|
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
104 |
if (not -f $error_output) { return (0, "Didn't get any error output"); } |
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
105 |
|
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
106 |
my @retval = compare_files($desired, $error_output, $endlines); |
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
107 |
unlink($error_output); |
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
876
diff
changeset
|
108 |
return @retval; |
750
238675cfa788
Added unit test framework stub for error testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
742
diff
changeset
|
109 |
}; |
736
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
110 |
|
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
111 |
my $totaltests = 0; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
112 |
my $pass = 0; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
113 |
my $fail = 0; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
114 |
my $skip = 0; |
888
3f13aefabfce
Make failed tests more clear in the output.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
115 |
my @fails = (); |
736
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
116 |
|
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
117 |
my $result = ''; |
876
e005b1f38952
Changed where we spawn mojoshader-compiler from, for __FILE__ testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
750
diff
changeset
|
118 |
chdir($testdir) or die("Failed to chdir('$testdir'): $!\n"); |
736
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
119 |
foreach (@modules) { |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
120 |
my $module = $_; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
121 |
foreach (keys %tests) { |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
122 |
my $testtype = $_; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
123 |
my $fn = $tests{$_}; |
876
e005b1f38952
Changed where we spawn mojoshader-compiler from, for __FILE__ testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
750
diff
changeset
|
124 |
my $d = "$module/$testtype"; |
736
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
125 |
next if (not -d $d); # no tests at the moment. |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
126 |
opendir(TESTDIR, $d) || die("Failed to open dir '$d': $!\n"); |
889
d3ecff60a3f5
List subsection in the condensed error output.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
127 |
my $subsection = " ... $module / $testtype ...\n"; |
d3ecff60a3f5
List subsection in the condensed error output.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
128 |
print($subsection); |
d3ecff60a3f5
List subsection in the condensed error output.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
129 |
my $addedsubsection = 0; |
736
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
130 |
my $fname = readdir(TESTDIR); |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
131 |
while (defined $fname) { |
888
3f13aefabfce
Make failed tests more clear in the output.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
132 |
my $isfail = 0; |
736
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
133 |
my $origfname = $fname; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
134 |
$fname = readdir(TESTDIR); # set for next iteration. |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
135 |
next if (-d $origfname); |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
136 |
next if ($origfname =~ /\.correct\Z/); |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
137 |
my $fullfname = "$d/$origfname"; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
138 |
my ($rc, $reason) = &$fn($module, $fullfname); |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
139 |
if ($rc == 1) { |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
140 |
$result = 'PASS'; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
141 |
$pass++; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
142 |
} elsif ($rc == 0) { |
888
3f13aefabfce
Make failed tests more clear in the output.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
143 |
$isfail = 1; |
736
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
144 |
$result = 'FAIL'; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
145 |
$fail++; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
146 |
} elsif ($rc == -1) { |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
147 |
$result = 'SKIP'; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
148 |
$skip++; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
149 |
} |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
150 |
|
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
151 |
if (defined $reason) { |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
152 |
$reason = " ($reason)"; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
153 |
} else { |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
154 |
$reason = ''; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
155 |
} |
888
3f13aefabfce
Make failed tests more clear in the output.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
156 |
my $output = "$result ${origfname}${reason}\n"; |
3f13aefabfce
Make failed tests more clear in the output.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
157 |
print($output); |
889
d3ecff60a3f5
List subsection in the condensed error output.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
158 |
|
d3ecff60a3f5
List subsection in the condensed error output.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
159 |
if ($isfail) { |
d3ecff60a3f5
List subsection in the condensed error output.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
160 |
if (!$addedsubsection) { |
d3ecff60a3f5
List subsection in the condensed error output.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
161 |
$addedsubsection = 1; |
d3ecff60a3f5
List subsection in the condensed error output.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
162 |
push(@fails, $subsection); |
d3ecff60a3f5
List subsection in the condensed error output.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
163 |
} |
d3ecff60a3f5
List subsection in the condensed error output.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
164 |
push(@fails, $output); |
d3ecff60a3f5
List subsection in the condensed error output.
Ryan C. Gordon <icculus@icculus.org>
parents:
888
diff
changeset
|
165 |
} |
736
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
166 |
|
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
167 |
$totaltests++; |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
168 |
} |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
169 |
closedir(TESTDIR); |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
170 |
} |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
171 |
} |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
172 |
|
888
3f13aefabfce
Make failed tests more clear in the output.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
173 |
if (scalar(@fails)) { |
3f13aefabfce
Make failed tests more clear in the output.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
174 |
print("\n\n"); |
3f13aefabfce
Make failed tests more clear in the output.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
175 |
print("*************************************************************\n"); |
3f13aefabfce
Make failed tests more clear in the output.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
176 |
print("*************************************************************\n"); |
3f13aefabfce
Make failed tests more clear in the output.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
177 |
print("** SOME TESTS FAILED! PLEASE CORRECT THE FOLLOWING ISSUES. **\n"); |
3f13aefabfce
Make failed tests more clear in the output.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
178 |
print("*************************************************************\n"); |
3f13aefabfce
Make failed tests more clear in the output.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
179 |
print("*************************************************************\n"); |
3f13aefabfce
Make failed tests more clear in the output.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
180 |
print("\n"); |
3f13aefabfce
Make failed tests more clear in the output.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
181 |
foreach (@fails) { |
3f13aefabfce
Make failed tests more clear in the output.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
182 |
print $_; |
3f13aefabfce
Make failed tests more clear in the output.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
183 |
} |
3f13aefabfce
Make failed tests more clear in the output.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
184 |
print("\n\n"); |
3f13aefabfce
Make failed tests more clear in the output.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
185 |
} |
3f13aefabfce
Make failed tests more clear in the output.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
186 |
|
736
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
187 |
print("\n$totaltests tests, $pass passed, $fail failed, $skip skipped.\n\n"); |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
188 |
|
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
189 |
exit(($fail > 0) ? 1 : 0); |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
190 |
|
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
191 |
# end if run_tests.pl ... |
a392aabaa21c
Initial framework for unit testing.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
192 |