1 module tests.it.runtime.dub;
2 
3 
4 import tests.it.runtime;
5 import reggae.reggae;
6 import std.path;
7 
8 
9 private string prepareTestPath(in string projectName) {
10     const testPath = newTestDir;
11     const projPath = buildPath(origPath, "tests", "projects", projectName);
12     copyProjectFiles(projPath, testPath);
13     return testPath;
14 }
15 
16 @("dub project with no reggaefile ninja")
17 @Tags(["dub", "ninja"])
18 unittest {
19 
20     with(immutable ReggaeSandbox()) {
21         copyProject("dub");
22         shouldNotExist("reggaefile.d");
23         runReggae("-b", "ninja", "--dflags=-g -debug");
24         shouldExist("reggaefile.d");
25         auto output = ninja.shouldExecuteOk(testPath);
26         output.shouldContain("-g -debug");
27 
28         shouldSucceed("atest").shouldEqual(
29             ["Why hello!",
30              "",
31              "[0, 0, 0, 4]",
32              "I'm immortal!"]
33         );
34 
35         // there's only one UT in main.d which always fails
36         shouldFail("ut");
37     }
38 }
39 
40 @("dub project with no reggaefile tup")
41 @Tags(["dub", "tup"])
42 unittest {
43     with(immutable ReggaeSandbox()) {
44         copyProject("dub");
45         runReggae("-b", "tup", "--dflags=-g -debug").
46             shouldThrowWithMessage("dub integration not supported with the tup backend");
47     }
48 }
49 
50 @("dub project with no reggaefile and prebuild command")
51 @Tags(["dub", "ninja"])
52 unittest {
53     with(immutable ReggaeSandbox()) {
54         copyProject("dub_prebuild");
55         runReggae("-b", "ninja", "--dflags=-g -debug");
56         ninja.shouldExecuteOk(testPath);
57         shouldSucceed("ut");
58     }
59 }
60 
61 
62 @("project with dependencies not on file system already no dub.selections.json")
63 @Tags(["dub", "ninja"])
64 unittest {
65 
66     import std.file: exists, rmdirRecurse;
67     import std.process: environment;
68     import std.path: buildPath;
69 
70     const cerealedDir = buildPath(environment["HOME"], ".dub/packages/cerealed-0.6.8");
71     if(cerealedDir.exists)
72         rmdirRecurse(cerealedDir);
73 
74     with(immutable ReggaeSandbox()) {
75         writeFile("dub.json", `
76 {
77   "name": "depends_on_cerealed",
78   "license": "MIT",
79   "targetType": "executable",
80   "dependencies": { "cerealed": "==0.6.8" }
81 }`);
82 
83         runReggae("-b", "ninja");
84     }
85 }
86 
87 @("project with dependencies not on file system already with dub.selections.json")
88 @Tags(["dub", "ninja"])
89 unittest {
90 
91     import std.file: exists, rmdirRecurse;
92     import std.process: environment;
93     import std.path: buildPath;
94 
95     const cerealedDir = buildPath(environment["HOME"], ".dub/packages/cerealed-0.6.8");
96     if(cerealedDir.exists)
97         rmdirRecurse(cerealedDir);
98 
99     with(immutable ReggaeSandbox()) {
100         writeFile("dub.json", `
101 {
102   "name": "depends_on_cerealed",
103   "license": "MIT",
104   "targetType": "executable",
105   "dependencies": { "cerealed": "==0.6.8" }
106 }`);
107 
108         writeFile("dub.selections.json", `
109 {
110         "fileVersion": 1,
111         "versions": {
112                 "cerealed": "0.6.8",
113         }
114 }
115 `);
116 
117         runReggae("-b", "ninja");
118     }
119 }
120 
121 @("simple dub project with no main function but with unit tests")
122 @Tags(["dub", "ninja"])
123 unittest {
124     import std.file: mkdirRecurse;
125     import std.path: buildPath;
126 
127     with(immutable ReggaeSandbox()) {
128         writeFile("dub.json", `
129             {
130               "name": "depends_on_cerealed",
131               "license": "MIT",
132               "targetType": "executable",
133               "dependencies": { "cerealed": "==0.6.8" }
134             }`);
135 
136         writeFile("reggaefile.d", q{
137             import reggae;
138             mixin build!(dubTestTarget!(Flags("-g -debug")));
139         });
140 
141         mkdirRecurse(buildPath(testPath, "source"));
142         writeFile("source/foo.d", `unittest { assert(false); }`);
143         runReggae("-b", "ninja");
144         ninja.shouldExecuteOk(testPath);
145 
146         shouldFail("ut");
147     }
148 }