From 1ef555e004e81fb7aa5c215837bf2d737f01564a Mon Sep 17 00:00:00 2001 From: Remi Thebault Date: Sat, 12 Aug 2023 14:36:47 +0200 Subject: [PATCH] add test for the --deep switch --- test/pr2647-build-deep/.gitignore | 2 + test/pr2647-build-deep/.no_test | 0 test/pr2647-build-deep/dub.sdl | 2 + test/pr2647-build-deep/pack/dub.sdl | 3 ++ test/pr2647-build-deep/pack/source/lib.d | 14 +++++ .../source/test_build_deep.d | 53 +++++++++++++++++++ 6 files changed, 74 insertions(+) create mode 100644 test/pr2647-build-deep/.gitignore create mode 100644 test/pr2647-build-deep/.no_test create mode 100644 test/pr2647-build-deep/dub.sdl create mode 100644 test/pr2647-build-deep/pack/dub.sdl create mode 100644 test/pr2647-build-deep/pack/source/lib.d create mode 100644 test/pr2647-build-deep/source/test_build_deep.d diff --git a/test/pr2647-build-deep/.gitignore b/test/pr2647-build-deep/.gitignore new file mode 100644 index 000000000..a71baffd9 --- /dev/null +++ b/test/pr2647-build-deep/.gitignore @@ -0,0 +1,2 @@ +dubhome/ +pr2647-build-deep diff --git a/test/pr2647-build-deep/.no_test b/test/pr2647-build-deep/.no_test new file mode 100644 index 000000000..e69de29bb diff --git a/test/pr2647-build-deep/dub.sdl b/test/pr2647-build-deep/dub.sdl new file mode 100644 index 000000000..639f6d5ab --- /dev/null +++ b/test/pr2647-build-deep/dub.sdl @@ -0,0 +1,2 @@ +name "pr2647-build-deep"; +targetType "executable"; diff --git a/test/pr2647-build-deep/pack/dub.sdl b/test/pr2647-build-deep/pack/dub.sdl new file mode 100644 index 000000000..d173b9a51 --- /dev/null +++ b/test/pr2647-build-deep/pack/dub.sdl @@ -0,0 +1,3 @@ +name "pack" +targetType "staticLibrary" +dependency "urld" version="==2.1.1" diff --git a/test/pr2647-build-deep/pack/source/lib.d b/test/pr2647-build-deep/pack/source/lib.d new file mode 100644 index 000000000..868cb18e4 --- /dev/null +++ b/test/pr2647-build-deep/pack/source/lib.d @@ -0,0 +1,14 @@ +module lib; + +import url; + +string getDlangUrl() +{ + URL url; + with(url) + { + scheme = "https"; + host = "dlang.org"; + } + return url.toString(); +} diff --git a/test/pr2647-build-deep/source/test_build_deep.d b/test/pr2647-build-deep/source/test_build_deep.d new file mode 100644 index 000000000..79e4a41e3 --- /dev/null +++ b/test/pr2647-build-deep/source/test_build_deep.d @@ -0,0 +1,53 @@ +module test_build_deep; + +import std.array; +import std.file; +import std.path; +import std.process; +import std.stdio; + +void main() +{ + const dubhome = __FILE_FULL_PATH__.dirName().dirName().buildNormalizedPath("dubhome"); + const packdir = __FILE_FULL_PATH__.dirName().dirName().buildNormalizedPath("pack"); + const dub = absolutePath(environment["DUB"]); + + if (exists(dubhome)) + { + rmdirRecurse(dubhome); + } + + scope (success) + { + // leave dubhome in the tree for analysis in case of failure + rmdirRecurse(dubhome); + } + + const string[string] env = [ + "DUB_HOME": dubhome, + ]; + + // testing the regular way first: `dub build` only builds what is needed + // (urld is downloaded but not built) + const dubBuildProg = [dub, "build"]; + writefln("running %s ...", dubBuildProg.join(" ")); + auto dubBuild = spawnProcess(dubBuildProg, stdin, stdout, stderr, env, Config.none, packdir); + wait(dubBuild); + assert(exists(buildPath(dubhome, "cache", "pack"))); + assert(isDir(buildPath(dubhome, "cache", "pack"))); + assert(exists(buildPath(dubhome, "packages", "urld"))); + assert(isDir(buildPath(dubhome, "packages", "urld"))); + assert(!exists(buildPath(dubhome, "cache", "urld"))); + + // now testing the --deep switch: `dub build --deep` will build urld + const dubBuildDeepProg = [dub, "build", "--deep"]; + writefln("running %s ...", dubBuildDeepProg.join(" ")); + auto dubBuildDeep = spawnProcess(dubBuildDeepProg, stdin, stdout, stderr, env, Config.none, packdir); + wait(dubBuildDeep); + assert(exists(buildPath(dubhome, "cache", "pack"))); + assert(isDir(buildPath(dubhome, "cache", "pack"))); + assert(exists(buildPath(dubhome, "packages", "urld"))); + assert(isDir(buildPath(dubhome, "packages", "urld"))); + assert(exists(buildPath(dubhome, "cache", "urld"))); + assert(isDir(buildPath(dubhome, "cache", "urld"))); +}