1 module tests.ut.rules.link;
2 
3 
4 import reggae;
5 import reggae.path: buildPath;
6 import unit_threaded;
7 
8 
9 @("shell commands") unittest {
10     import reggae.config: gDefaultOptions, dCompiler;
11 
12     version(Windows) {
13         version(DigitalMars)
14             enum defaultDCModel = " -m32mscoff";
15         else
16             enum defaultDCModel = null;
17     } else
18         enum defaultDCModel = null;
19 
20     auto objTarget = link(ExeName("myapp"), [Target("foo.o"), Target("bar.o")], Flags("-L-L"));
21     objTarget.shellCommand(gDefaultOptions.withProjectPath("/path/to")).shouldEqual(
22         dCompiler ~ defaultDCModel ~ " -ofmyapp -L-L " ~ buildPath("/path/to/foo.o") ~ " " ~ buildPath("/path/to/bar.o"));
23 
24     auto cppTarget = link(ExeName("cppapp"), [Target("foo.o", "", Target("foo.cpp"))], Flags("--sillyflag"));
25     //since foo.o is not a leaf target, the path should not appear (it's created in the build dir)
26     version(Windows)
27         enum expectedCpp = "cl.exe /nologo /Focppapp --sillyflag foo.o";
28     else
29         enum expectedCpp = "g++ -o cppapp --sillyflag foo.o";
30     cppTarget.shellCommand(gDefaultOptions.withProjectPath("/foo/bar")).shouldEqual(expectedCpp);
31 
32     auto cTarget = link(ExeName("capp"), [Target("bar.o", "", Target("bar.c"))]);
33     //since foo.o is not a leaf target, the path should not appear (it's created in the build dir)
34     version(Windows)
35         enum expectedC = "cl.exe /nologo /Focapp  bar.o";
36     else
37         enum expectedC = "gcc -o capp  bar.o";
38     cTarget.shellCommand(gDefaultOptions.withProjectPath("/foo/bar")).shouldEqual(expectedC);
39 }
40 
41 
42 @("include flags in project dir") unittest {
43     auto obj = objectFile(SourceFile("src/foo.c"),
44                           Flags("-include $project/includes/header.h"));
45     auto app = link(ExeName("app"), [obj]);
46     auto bld = Build(app);
47     import reggae.config: gDefaultOptions;
48     enum objPath = buildPath(".reggae/objs/app.objs/src/foo" ~ objExt);
49     version(Windows) {
50         enum expected = `cl.exe /nologo -include \path\to/includes/header.h  /showIncludes ` ~
51                         `/Fo` ~ objPath ~ ` -c \path\to\src\foo.c`;
52     } else {
53         enum expected = "gcc -include /path/to/includes/header.h  -MMD -MT " ~ objPath ~ " -MF " ~ objPath ~ ".dep " ~
54                         "-o " ~ objPath ~ " -c /path/to/src/foo.c";
55     }
56     bld.targets[0].dependencyTargets[0].shellCommand(gDefaultOptions.withProjectPath("/path/to")).shouldEqual(expected);
57 }
58 
59 @("template link") unittest {
60     string[] flags;
61     link!(ExeName("app"), () => [Target("foo.o"), Target("bar.o")]).shouldEqual(
62         Target("app",
63                Command(CommandType.link, assocListT("flags", flags)),
64                [Target("foo.o"), Target("bar.o")]));
65 }