1 module tests.ut.dependencies;
2 
3 import unit_threaded;
4 import reggae.dependencies: dMainDepSrcs;
5 import reggae.backend.binary: dependenciesFromFile;
6 import reggae.dcompile: dMainDependencies, dependenciesToFile;
7 import std.array;
8 
9 
10 void testEmpty() {
11     "".dMainDependencies.shouldEqual([]);
12 }
13 
14 void testImports() {
15     "import     std.stdio\t(/inst/std/stdio.d)\n".dMainDependencies.shouldEqual([]);
16     "import     std.stdio\t(/int/std/stdio.d)\nimport    foo.bar\t(/foo/bar.d)".
17         dMainDependencies.shouldEqual(["/foo/bar.d"]);
18 }
19 
20 
21 void testFiles() {
22     "file      foo.d\t(/path/to/foo.d)".dMainDependencies.shouldEqual(["/path/to/foo.d"]);
23 }
24 
25 
26 void testSrcs() {
27     "import     std.stdio\t(/inst/std/stdio.d)\n".dMainDepSrcs.shouldEqual([]);
28     "import     std.stdio\t(/int/std/stdio.d)\nimport    foo.bar\t(/foo/bar.d)".
29         dMainDepSrcs.shouldEqual(["/foo/bar.d"]);
30     "file      foo.d\t(/path/to/foo.d)".dMainDepSrcs.shouldEqual([]);
31 }
32 
33 
34 void testEtcLinux() {
35 
36     ["semantic2 main",
37      "semantic3 main",
38      "import    etc.linux.memoryerror (/usr/include/dlang/dmd/etc/linux/memoryerror.d)",
39      "import    core.sys.posix.ucontext       (/usr/include/dlang/dmd/core/sys/posix/ucontext.d)"].
40         join("\n").dMainDepSrcs.shouldEqual([]);
41 }
42 
43 
44 void testToFile() {
45     auto deps = ["/foo/bar.d", "/foo/baz.d"];
46     dependenciesToFile("foo.o", deps).shouldEqual(
47         ["foo.o: \\",
48          "/foo/bar.d /foo/baz.d"]);
49 }
50 
51 
52 void testFromFile() {
53     immutable depFileLines = [
54         "objs/calc.objs/src/cpp/maths.o: \\",
55         "/home/aalvesne/coding/d/reggae/tmp/aruba/mixproj/src/cpp/maths.cpp " ~
56         "/home/aalvesne/coding/d/reggae/tmp/aruba/mixproj/headers/maths.hpp"];
57     dependenciesFromFile(depFileLines).shouldEqual(
58         [ "/home/aalvesne/coding/d/reggae/tmp/aruba/mixproj/src/cpp/maths.cpp",
59           "/home/aalvesne/coding/d/reggae/tmp/aruba/mixproj/headers/maths.hpp"]);
60 
61     string[] noDeps;
62     dependenciesFromFile(noDeps).shouldEqual([]);
63 }
64 
65 @("multiple backslashes")
66 unittest {
67     dependenciesFromFile(
68         [`foo.o: \`,
69          ` foo.c \`,
70          ` foo.h \`,
71          `bar.h`])
72         .shouldEqual(["foo.c", "foo.h", "bar.h"]);
73 }