1 module tests.drules;
2 
3 
4 import reggae;
5 import unit_threaded;
6 import std.algorithm;
7 
8 
9 void testDCompileNoIncludePathsNinja() {
10     const build = Build(objectFile(SourceFile("path/to/src/foo.d")));
11     const ninja = Ninja(build, "/tmp/myproject");
12     ninja.buildEntries.shouldEqual(
13         [NinjaEntry("build path/to/src/foo.o: _dcompile /tmp/myproject/path/to/src/foo.d",
14                     ["DEPFILE = path/to/src/foo.o.dep"])]);
15 }
16 
17 
18 void testDCompileIncludePathsNinja() {
19     const build = Build(objectFile(SourceFile("path/to/src/foo.d"),
20                                    Flags("-O"),
21                                    ImportPaths(["path/to/src", "other/path"])));
22     const ninja = Ninja(build, "/tmp/myproject");
23     ninja.buildEntries.shouldEqual(
24         [NinjaEntry("build path/to/src/foo.o: _dcompile /tmp/myproject/path/to/src/foo.d",
25                     ["includes = -I/tmp/myproject/path/to/src -I/tmp/myproject/other/path",
26                      "flags = -O",
27                      "DEPFILE = path/to/src/foo.o.dep"])]);
28 }
29 
30 void testDCompileIncludePathsMake() {
31     const build = Build(objectFile(SourceFile("path/to/src/foo.d"),
32                                    Flags("-O"),
33                                    ImportPaths(["path/to/src", "other/path"])));
34     build.targets.array[0].shellCommand("/tmp/myproject").shouldEqual(".reggae/dcompile --objFile=path/to/src/foo.o --depFile=path/to/src/foo.o.dep dmd -O -I/tmp/myproject/path/to/src -I/tmp/myproject/other/path  /tmp/myproject/path/to/src/foo.d");
35 }
36 
37 
38 void testDLinkNinja() {
39     const build = Build(link(ExeName("bin/lefoo"), [Target("leobj.o")], Flags("-lib")));
40     const ninja = Ninja(build, "/dir/stuff");
41     ninja.buildEntries.shouldEqual(
42         [NinjaEntry("build bin/lefoo: _ulink /dir/stuff/leobj.o",
43                     ["flags = -lib"])]);
44 }
45 
46 void testDCompileWithMultipleFilesMake() {
47     const build = Build(dlangPackageObjectFilesPerPackage(["path/to/src/foo.d", "path/to/src/bar.d", "other/weird.d"],
48                                               "-O", ["path/to/src", "other/path"]));
49     build.targets.map!(a => a.shellCommand("/tmp/myproject")).shouldBeSameSetAs(
50         [".reggae/dcompile --objFile=other.o --depFile=other.o.dep dmd -O -I/tmp/myproject/path/to/src -I/tmp/myproject/other/path  /tmp/myproject/other/weird.d",
51          ".reggae/dcompile --objFile=path/to/src.o --depFile=path/to/src.o.dep dmd -O -I/tmp/myproject/path/to/src -I/tmp/myproject/other/path  /tmp/myproject/path/to/src/foo.d /tmp/myproject/path/to/src/bar.d"
52             ]
53         );
54 }
55 
56 void testDCompileWithMultipleFilesNinja() {
57     const build = Build(dlangPackageObjectFilesPerPackage(["path/to/src/foo.d", "path/to/src/bar.d", "other/weird.d"],
58                                               "-O", ["path/to/src", "other/path"]));
59     auto ninja = Ninja(build, "/tmp/myproject"); //can't be const because of `sort` below
60     NinjaEntry[] entries;
61 
62     ninja.buildEntries.shouldBeSameSetAs(
63         [
64 
65             NinjaEntry("build other.o: _dcompile /tmp/myproject/other/weird.d",
66                        ["includes = -I/tmp/myproject/path/to/src -I/tmp/myproject/other/path",
67                         "flags = -O",
68                         "DEPFILE = path/to/src/foo.o.dep"]),
69 
70             NinjaEntry("build path/to/src.o: _dcompile /tmp/myproject/path/to/src/foo.d /tmp/myproject/path/to/src/bar.d",
71                        ["includes = -I/tmp/myproject/path/to/src -I/tmp/myproject/other/path",
72                         "flags = -O",
73                         "DEPFILE = path/to/src/foo.o.dep"]),
74 
75             ]);
76 }
77 
78 
79 void testLink() {
80     const objTarget = link(ExeName("myapp"), [Target("foo.o"), Target("bar.o")], Flags("-L-L"));
81     objTarget.shellCommand("/path/to").shouldEqual("dmd -ofmyapp -L-L /path/to/foo.o /path/to/bar.o");
82 
83     const cppTarget = link(ExeName("cppapp"), [Target("foo.o", "", Target("foo.cpp"))], Flags("--sillyflag"));
84     //since foo.o is not a leaf target, the path should not appear (it's created in the build dir)
85     cppTarget.shellCommand("/foo/bar").shouldEqual("g++ -o cppapp --sillyflag foo.o");
86 
87     const cTarget = link(ExeName("capp"), [Target("bar.o", "", Target("bar.c"))]);
88     //since foo.o is not a leaf target, the path should not appear (it's created in the build dir)
89     cTarget.shellCommand("/foo/bar").shouldEqual("gcc -o capp  bar.o");
90 }
91 
92 
93 void testObjectFilesEmpty() {
94     dlangPackageObjectFilesPerPackage([]).shouldEqual([]);
95     dlangPackageObjectFilesPerModule([]).shouldEqual([]);
96 }