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