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