1 module tests.ut.high_rules;
2 
3 
4 import reggae;
5 import reggae.options;
6 import unit_threaded;
7 import std.typecons: No;
8 
9 
10 void testCObjectFile() {
11     immutable fileName = "foo.c";
12     auto obj = objectFile(SourceFile(fileName),
13                            Flags("-g -O0"),
14                            IncludePaths(["myhdrs", "otherhdrs"]));
15     auto cmd = Command(CommandType.compile,
16                         assocListT("includes", ["-I$project/myhdrs", "-I$project/otherhdrs"],
17                                    "flags", ["-g", "-O0"],
18                                    "DEPFILE", ["foo.o.dep"]));
19 
20     obj.shouldEqual(Target("foo.o", cmd, [Target(fileName)]));
21 
22     auto options = Options();
23     options.cCompiler = "weirdcc";
24     options.projectPath = "/project";
25     obj.shellCommand(options).shouldEqual(
26         "weirdcc -g -O0 -I/project/myhdrs -I/project/otherhdrs -MMD -MT foo.o -MF foo.o.dep -o foo.o -c /project/foo.c");
27 }
28 
29 void testCppObjectFile() {
30     foreach(ext; ["cpp", "CPP", "cc", "cxx", "C", "c++"]) {
31         immutable fileName = "foo." ~ ext;
32         auto obj = objectFile(SourceFile(fileName),
33                                Flags("-g -O0"),
34                                IncludePaths(["myhdrs", "otherhdrs"]));
35         auto cmd = Command(CommandType.compile,
36                             assocListT("includes", ["-I$project/myhdrs", "-I$project/otherhdrs"],
37                                        "flags", ["-g", "-O0"],
38                                        "DEPFILE", ["foo.o.dep"]));
39 
40         obj.shouldEqual(Target("foo.o", cmd, [Target(fileName)]));
41     }
42 }
43 
44 
45 void testDObjectFile() {
46     auto obj = objectFile(SourceFile("foo.d"),
47                            Flags("-g -debug"),
48                            ImportPaths(["myhdrs", "otherhdrs"]),
49                            StringImportPaths(["strings", "otherstrings"]));
50     auto cmd = Command(CommandType.compile,
51                         assocListT("includes", ["-I$project/myhdrs", "-I$project/otherhdrs"],
52                                    "flags", ["-g", "-debug"],
53                                    "stringImports", ["-J$project/strings", "-J$project/otherstrings"],
54                                    "DEPFILE", ["foo.o.dep"]));
55 
56     obj.shouldEqual(Target("foo.o", cmd, [Target("foo.d")]));
57 }
58 
59 
60 void testBuiltinTemplateDeps() {
61     import reggae.config;
62 
63     Command.builtinTemplate(CommandType.compile, Language.C, gDefaultOptions).shouldEqual(
64         "gcc $flags $includes -MMD -MT $out -MF $out.dep -o $out -c $in");
65 
66     Command.builtinTemplate(CommandType.compile, Language.D, gDefaultOptions).shouldEqual(
67         ".reggae/dcompile --objFile=$out --depFile=$out.dep " ~
68          "dmd $flags $includes $stringImports $in");
69 
70 }
71 
72 void testBuiltinTemplateNoDeps() {
73     import reggae.config;
74 
75     Command.builtinTemplate(CommandType.compile, Language.C, gDefaultOptions, No.dependencies).shouldEqual(
76         "gcc $flags $includes -o $out -c $in");
77 
78     Command.builtinTemplate(CommandType.compile, Language.D, gDefaultOptions, No.dependencies).shouldEqual(
79         "dmd $flags $includes $stringImports -of$out -c $in");
80 
81 }