1 module tests.ut.high_rules;
2 
3 
4 import reggae;
5 import reggae.options;
6 import reggae.path: buildPath;
7 import unit_threaded;
8 
9 
10 version(Windows) {
11     version(DigitalMars)
12         immutable defaultDCModel = " -m32mscoff";
13     else
14         immutable defaultDCModel = "";
15 } else
16     enum defaultDCModel = null;
17 
18 @("C object file") unittest {
19     immutable fileName = "foo.c";
20     enum objPath = "foo" ~ objExt;
21     auto obj = objectFile(SourceFile(fileName),
22                            Flags("-g -O0"),
23                            IncludePaths(["myhdrs", "otherhdrs"]));
24     auto cmd = Command(CommandType.compile,
25                         assocListT("includes", [buildPath("-I$project/myhdrs"), buildPath("-I$project/otherhdrs")],
26                                    "flags", ["-g", "-O0"],
27                                    "DEPFILE", [objPath ~ ".dep"]));
28 
29     obj.shouldEqual(Target(objPath, cmd, [Target(fileName)]));
30 
31     auto options = Options();
32     options.cCompiler = "weirdcc";
33     options.projectPath = "/project";
34     version(Windows) {
35         enum expected = `weirdcc /nologo -g -O0 -I\project\myhdrs -I\project\otherhdrs /showIncludes ` ~
36                         `/Fofoo.obj -c \project\foo.c`;
37     } else {
38         enum expected = "weirdcc -g -O0 -I/project/myhdrs -I/project/otherhdrs -MMD -MT foo.o -MF foo.o.dep " ~
39                         "-o foo.o -c /project/foo.c";
40     }
41     obj.shellCommand(options).shouldEqual(expected);
42 }
43 
44 @("C++ object file") unittest {
45     foreach(ext; ["cpp", "CPP", "cc", "cxx", "C", "c++"]) {
46         immutable fileName = "foo." ~ ext;
47         enum objPath = "foo" ~ objExt;
48         auto obj = objectFile(SourceFile(fileName),
49                                Flags("-g -O0"),
50                                IncludePaths(["myhdrs", "otherhdrs"]));
51         auto cmd = Command(CommandType.compile,
52                             assocListT("includes", [buildPath("-I$project/myhdrs"), buildPath("-I$project/otherhdrs")],
53                                        "flags", ["-g", "-O0"],
54                                        "DEPFILE", [objPath ~ ".dep"]));
55 
56         obj.shouldEqual(Target(objPath, cmd, [Target(fileName)]));
57     }
58 }
59 
60 
61 @("D object file") unittest {
62     auto obj = objectFile(SourceFile("foo.d"),
63                            Flags("-g -debug"),
64                            ImportPaths(["myhdrs", "otherhdrs"]),
65                            StringImportPaths(["strings", "otherstrings"]));
66     enum objPath = "foo" ~ objExt;
67     auto cmd = Command(CommandType.compile,
68                         assocListT("includes", [buildPath("-I$project/myhdrs"), buildPath("-I$project/otherhdrs")],
69                                    "flags", ["-g", "-debug"],
70                                    "stringImports", [buildPath("-J$project/strings"), buildPath("-J$project/otherstrings")],
71                                    "DEPFILE", [objPath ~ ".dep"]));
72 
73     obj.shouldEqual(Target(objPath, cmd, [Target("foo.d")]));
74 }
75 
76 
77 @("builtinTemplate deps") unittest {
78     import reggae.config;
79 
80     version(Windows)
81         enum expectedC = "cl.exe /nologo $flags $includes /showIncludes /Fo$out -c $in";
82     else
83         enum expectedC = "gcc $flags $includes -MMD -MT $out -MF $out.dep -o $out -c $in";
84     Command.builtinTemplate(CommandType.compile, Language.C, gDefaultOptions).shouldEqual(expectedC);
85 
86     Command.builtinTemplate(CommandType.compile, Language.D, gDefaultOptions).shouldEqual(
87         buildPath(".reggae/dcompile") ~ " --objFile=$out --depFile=$out.dep " ~
88          dCompiler ~ defaultDCModel ~ " $flags $includes $stringImports $in");
89 
90 }
91 
92 @("builtinTemplate no deps") unittest {
93     import reggae.config;
94     import std.typecons: No;
95 
96     version(Windows)
97         enum expectedC = "cl.exe /nologo $flags $includes /Fo$out -c $in";
98     else
99         enum expectedC = "gcc $flags $includes -o $out -c $in";
100     Command.builtinTemplate(CommandType.compile, Language.C, gDefaultOptions, No.dependencies).shouldEqual(expectedC);
101 
102     Command.builtinTemplate(CommandType.compile, Language.D, gDefaultOptions, No.dependencies).shouldEqual(
103         dCompiler ~ defaultDCModel ~ " $flags $includes $stringImports -of$out -c $in");
104 
105 }