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