1 module tests.it.rules.json_build;
2 
3 import tests.it;
4 import reggae.json_build;
5 import reggae.path: buildPath;
6 import std.file;
7 import std.stdio: File;
8 
9 immutable linkJsonStr =
10 `
11         [{"type": "fixed",
12           "command": {"type": "link", "flags": ["-L-M"]},
13           "outputs": ["myapp"],
14           "dependencies": {
15               "type": "dynamic",
16               "func": "objectFiles",
17               "src_dirs": ["src"],
18               "exclude_dirs": [],
19               "src_files": [],
20               "exclude_files": [],
21               "flags": ["-g"],
22               "includes": ["src"],
23               "string_imports": []},
24           "implicits": {
25               "type": "fixed",
26               "targets": []}}]
27 `;
28 
29 
30 @("link with no files")
31 unittest {
32     const testPath = newTestDir;
33     mkdir(buildPath(testPath, "src"));
34 
35     jsonToBuild(testPath, linkJsonStr).shouldEqual(
36         Build(Target("myapp",
37                      Command(CommandType.link, assocListT("flags", ["-L-M"]))))
38     );
39 }
40 
41 @("link with files")
42 unittest {
43     import reggae.config;
44     const testPath = newTestDir;
45     setOptions(getOptions(["reggae", "-b", "ninja", "--per-module", "testPath"]));
46     mkdir(buildPath(testPath, "src"));
47 
48     foreach(fileName; ["foo.d", "bar.d"]) {
49         File(buildPath(testPath, "src", fileName), "w").writeln;
50     }
51 
52     jsonToBuild(testPath, linkJsonStr).shouldEqual(
53         Build(Target("myapp",
54                      Command(CommandType.link, assocListT("flags", ["-L-M"])),
55                      [Target(buildPath("src/foo" ~ objExt),
56                              compileCommand(buildPath("src/foo.d"), ["-g"], [".", "src"]),
57                              [Target(buildPath("src/foo.d"))]),
58                       Target(buildPath("src/bar" ~ objExt),
59                              compileCommand(buildPath("src/bar.d"), ["-g"], [".", "src"]),
60                              [Target(buildPath("src/bar.d"))])]))
61     );
62 }