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