1 module tests.ut.drules;
2 
3 
4 import reggae;
5 import reggae.options;
6 import reggae.path: buildPath;
7 import reggae.backend.ninja;
8 import unit_threaded;
9 import std.algorithm;
10 import std.array;
11 
12 
13 @("DCompile no include paths Ninja") unittest {
14     auto build = Build(objectFile(SourceFile("path/to/src/foo.d")));
15     auto ninja = Ninja(build, "/tmp/myproject");
16     enum objPath = buildPath("path/to/src/foo" ~ objExt);
17     ninja.buildEntries.shouldEqual(
18         [NinjaEntry("build " ~ objPath ~ ": _dcompile " ~ buildPath("/tmp/myproject/path/to/src/foo.d"),
19                     [])]);
20 }
21 
22 
23 @("DCompile include paths Ninja") unittest {
24     auto build = Build(objectFile(SourceFile("path/to/src/foo.d"),
25                                    Flags("-O"),
26                                    ImportPaths(["path/to/src", "other/path"])));
27     auto ninja = Ninja(build, "/tmp/myproject");
28     enum objPath = buildPath("path/to/src/foo" ~ objExt);
29     ninja.buildEntries.shouldEqual(
30         [NinjaEntry("build " ~ objPath ~ ": _dcompile " ~ buildPath("/tmp/myproject/path/to/src/foo.d"),
31                     ["includes = -I" ~ buildPath("/tmp/myproject/path/to/src") ~ " -I" ~ buildPath("/tmp/myproject/other/path"),
32                      "flags = -O"])]);
33 }
34 
35 @("DCompile with spaces Ninja") unittest {
36     auto build = Build(objectFile(SourceFile("my src/foo.d"),
37                                    Flags(["-O", "-L/LIBPATH:my libs"]),
38                                    ImportPaths(["my src", "other/path"])));
39     auto ninja = Ninja(build, "/tmp/myproject");
40     enum objPath = buildPath("my src/foo" ~ objExt);
41     ninja.buildEntries.shouldEqual(
42         [NinjaEntry(`build ` ~ buildPath("my$ src/foo") ~ objExt ~ `: _dcompile ` ~ buildPath("/tmp/myproject/my$ src/foo.d"),
43                     [`includes = "-I` ~ buildPath("/tmp/myproject/my src") ~ `" -I` ~ buildPath("/tmp/myproject/other/path"),
44                      `flags = -O "-L/LIBPATH:my libs"`])]);
45 }
46 
47 version(DigitalMars) {
48                                                                                                                           @("DCompile include paths Make") unittest {
49                                                                                                                               import reggae.config: gDefaultOptions;
50 
51                                                                                                                               auto build = Build(objectFile(SourceFile("path/to/src/foo.d"),
52                                                                                                                                                              Flags("-O"),
53                                                                                                                                                              ImportPaths(["path/to/src", "other/path"])));
54                                                                                                                               version(Windows)
55                                                                                                                                   enum defaultDCModel = " -m32mscoff";
56                                                                                                                               else
57                                                                                                                                   enum defaultDCModel = null;
58                                                                                                                               enum objPath = buildPath("path/to/src/foo" ~ objExt);
59                                                                                                                               build.targets.array[0].shellCommand(gDefaultOptions.withProjectPath("/tmp/myproject")).shouldEqual(
60                                                                                                                                   buildPath(".reggae/dcompile") ~ " --objFile=" ~ objPath ~ " --depFile=" ~ objPath ~ ".dep dmd" ~ defaultDCModel ~ " -O " ~
61                                                                                                                                   "-I" ~ buildPath("/tmp/myproject/path/to/src") ~ " -I" ~ buildPath("/tmp/myproject/other/path") ~ "  " ~ buildPath("/tmp/myproject/path/to/src/foo.d"));
62     }
63 }
64 
65 @ShouldFail
66 @("dlangObjectFilesPerPackage")
67 unittest {
68     auto build = Build(dlangObjectFilesPerPackage(["path/to/src/foo.d",
69                                                    "path/to/src/bar.d",
70                                                    "other/weird.d"],
71                                                   ["-O"], ["path/to/src", "other/path"]));
72     build.shouldEqual(Build(Target("path/to/src.o",
73                                    compileCommand("path/to/src.d",
74                                                   ["-O"],
75                                                   ["path/to/src", "other/path"]),
76                                    [Target("path/to/src/foo.d"), Target("path/to/src/bar.d")]),
77                             Target("other.o",
78                                    compileCommand("other.d",
79                                                   ["-O"],
80                                                   ["path/to/src", "other/path"]),
81                                    [Target("other/weird.d")]),
82                           ));
83 }
84 
85 @("dlangObjectFilesPerPackage ..")
86 unittest {
87     auto build = Build(dlangObjectFilesPerModule(["/project/source/main.d",
88                                                   "/project/../../common/source/foo.d",
89                                                   "/project/../../common/source/bar.d",
90                                                  ]));
91     build.shouldEqual(Build(Target(buildPath("project/source/main" ~ objExt),
92                                    compileCommand("/project/source/main.d"),
93                                    Target("/project/source/main.d")),
94                             Target(buildPath("project/__/__/common/source/foo" ~ objExt),
95                                    compileCommand("/project/../../common/source/foo.d"),
96                                    Target("/project/../../common/source/foo.d")),
97                             Target(buildPath("project/__/__/common/source/bar" ~ objExt),
98                                    compileCommand("/project/../../common/source/bar.d"),
99                                    Target("/project/../../common/source/bar.d")),
100                           ));
101 }
102 
103 
104 @("Object files empty") unittest {
105     dlangObjectFilesPerPackage([]).shouldBeEmpty;
106     dlangObjectFilesPerModule([]).shouldBeEmpty;
107 }