-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_command_line_tool.d
71 lines (63 loc) · 1.66 KB
/
test_command_line_tool.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
import std.path;
import std.file;
import std.stdio;
import std.format : format;
import std.process : spawnShell, wait;
class SilentException : Exception
{
this()
{
super(null);
}
}
auto quit()
{
return new SilentException();
}
int main(string[] args)
{
try
{
return tryMain(args);
}
catch (SilentException)
{
return 1;
}
}
int tryMain(string[] args)
{
// TODO: move to std.path
version (Windows)
string exeExtention = ".exe";
else
string exeExtention;
auto rootDir = __FILE_FULL_PATH__.dirName;
auto outDir = rootDir.buildPath("out");
auto harExe = outDir.buildPath("har" ~ exeExtention);
auto testDir = rootDir.buildPath("test"); // workaround https://issues.dlang.org/show_bug.cgi?id=6138 : we need absolutePath
auto outTestDir = outDir.buildPath("test");
mkdirRecurse(outTestDir);
foreach (entry; dirEntries(testDir, "*.har", SpanMode.shallow))
{
auto file = entry.name;
auto name = file.baseName.setExtension(".expected");
run(format("%s %s --dir=%s", harExe, file, outTestDir.buildPath(name)));
auto expected = file.setExtension(".expected");
auto actual = outTestDir.buildPath(name);
run(format("diff --brief -r %s %s", expected, actual));
}
return 0;
}
void run(string command)
{
writefln("[SHELL] %s", command);
auto pid = spawnShell(command);
auto exitCode = wait(pid);
writeln("--------------------------------------------------------------------------------");
if (exitCode != 0)
{
writefln("last command exited with code %s", exitCode);
throw quit;
}
}