-
Notifications
You must be signed in to change notification settings - Fork 6
/
runtests.d
111 lines (88 loc) · 2.27 KB
/
runtests.d
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
106
107
108
109
110
111
import djehuty;
import io.console;
import spec.specification;
import spec.itemspecification;
import spec.packagespecification;
import spec.modulespecification;
import spec.test;
import parsing.options;
char[] usage = `runtests rev1
USAGE: runtests [(+|-)className]*
EXAMPLE: runtests +String +Random
runtests -Random`;
class Opts : OptionParser {
mixin Options!(
"-help", "View help and usage"
);
void onHelp() {
showUsage();
Djehuty.application.exit(0);
}
void onError(string token) {
Console.putln("YAY");
}
string[] modules() {
return _modules;
}
private:
string[] _modules;
}
// Do not change the class name, it is used in a test for djehuty proper!
class DjehutyTester : Application {
static this() { new DjehutyTester(); }
void onApplicationStart() {
options = new Opts();
if (options.modules is null) {
Console.putln();
// Go through every package
foreach(pack; Specification) {
_testPackage(pack);
}
}
}
private:
void _testPackage(PackageSpecification ps, string prior = "") {
foreach(PackageSpecification pack; ps) {
_testPackage(pack, prior ~ ps.name ~ ".");
}
foreach(ModuleSpecification mod; ps) {
_testModule(mod, prior ~ ps.name);
}
}
void _testModule(ModuleSpecification ms, string packName = "") {
Console.put(packName ~ "." ~ ms.name, " : ");
// Keep track of success over the module
int numFailures;
int numSuccesses;
foreach(item; ms) {
foreach(feature; item) {
auto tester = new Test(item, feature);
tester.run();
if (tester.failures > 0) {
Console.forecolor = Color.Red;
if (numFailures == 0) {
Console.putln("FAILED ");
}
Console.putln(" ".times((packName ~ "." ~ ms.name).length), " : ", item.name, " ", feature);
}
numFailures += tester.failures;
numSuccesses += tester.successes;
}
}
if (numFailures > 0) {
Console.forecolor = Color.Gray;
Console.put(packName ~ "." ~ ms.name, " : ");
Console.forecolor = Color.Red;
Console.put("FAILED ");
Console.forecolor = Color.Gray;
Console.putln(numSuccesses, " / ", numSuccesses+numFailures);
}
else {
Console.forecolor = Color.Green;
Console.put("PASSED ");
Console.forecolor = Color.Gray;
Console.putln("all ", numSuccesses, " tests");
}
}
Opts options;
}