-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathsdunit.d
116 lines (89 loc) · 2.33 KB
/
sdunit.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
112
113
114
115
116
module driver.dsunit;
import source.context;
immutable string[2] ResultStr = ["FAIL", "PASS"];
int main(string[] args) {
import util.main;
return runMain!run(args);
}
int run(Context context, string[] args) {
import sdc.config;
Config conf;
import config.build;
conf.buildGlobalConfig("sdconfig", context);
conf.enableUnittest = true;
string[] includePaths, linkerPaths;
import std.getopt;
auto help_info = getopt(
// sdfmt off
args, std.getopt.config.caseSensitive,
"I", "Include path", &includePaths,
"L", "Library path", &linkerPaths,
"O", "Optimization level", &conf.optLevel,
// sdfmt on
);
if (help_info.helpWanted || args.length == 1) {
import std.stdio;
writeln("The Snazzy D Compiler - Unit test JIT");
writeln("Usage: sdunit [options] file.d");
writeln("Options:");
foreach (option; help_info.options) {
writefln(
" %-16s %s",
// bug : optShort is empty if there is no long version
option.optShort.length
? option.optShort
: (option.optLong.length == 3)
? option.optLong[1 .. $]
: option.optLong,
option.help
);
}
return 0;
}
conf.includePaths = includePaths ~ conf.includePaths;
conf.linkerPaths = linkerPaths ~ conf.linkerPaths;
auto files = args[1 .. $];
// Cannot call the variable "sdc" or DMD complains about name clash
// with the sdc package from the import.
import sdc.sdc;
auto c = new SDC(context, files[0], conf, files);
import d.ir.symbol;
Module m = null;
bool returnCode = 0;
auto results = c.runUnittests();
if (results.length == 0) {
import std.stdio;
writeln("No test to run");
return 0;
}
import std.stdio;
write("Test results:");
foreach (r; results) {
if (!r.pass) {
returnCode = 1;
}
auto testModule = r.test.getModule();
if (m != testModule) {
m = testModule;
import source.context;
static void printModule(P)(Context c, P p) {
if (p.parent is null) {
import std.stdio;
write("\nModule ", p.toString(c));
return;
}
printModule(c, p.parent);
import std.stdio;
write(".", p.toString(c));
static if (is(P : Module)) {
writeln(":");
}
}
printModule(c.context, m);
}
auto name = r.test.name.toString(c.context);
import std.stdio;
writefln("\t%-24s %s", name, ResultStr[r.pass]);
}
return returnCode;
}