diff --git a/changelog/recursive-test.dd b/changelog/recursive-test.dd new file mode 100644 index 000000000..857b4a3d0 --- /dev/null +++ b/changelog/recursive-test.dd @@ -0,0 +1,3 @@ +Added dependency recursive test + +Dub now supports recursive test run. This feature can be activated by option `-r` or `--recursive`. diff --git a/source/dub/commandline.d b/source/dub/commandline.d index 077b9f699..58384bfdd 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -966,6 +966,7 @@ class TestCommand : PackageBuildCommand { bool m_combined = false; bool m_parallel = false; bool m_force = false; + bool m_recursive = false; } this() @@ -1009,6 +1010,9 @@ class TestCommand : PackageBuildCommand { args.getopt("f|force", &m_force, [ "Forces a recompilation even if the target is up to date" ]); + args.getopt("r|recursive", &m_recursive, [ + "Runs test including dependent packages." + ]); bool coverage = false; args.getopt("coverage", &coverage, [ "Enables code coverage statistics to be generated." @@ -1024,6 +1028,15 @@ class TestCommand : PackageBuildCommand { enforceUsage(free_args.length <= 1, "Expected one or zero arguments."); if (free_args.length >= 1) package_name = free_args[0]; + string[] tested_packages_cache; + return test(dub, package_name, app_args, tested_packages_cache); + } + + int test(Dub dub, string package_name, string[] app_args, ref string[] tested_packages) + { + if (tested_packages.canFind(package_name)) return 0; // prevent duplicate runs + tested_packages ~= package_name; + setupPackage(dub, package_name, "unittest"); GeneratorSettings settings; @@ -1041,6 +1054,13 @@ class TestCommand : PackageBuildCommand { settings.runArgs = app_args; dub.testProject(settings, m_buildConfig, NativePath(m_mainFile)); + if (m_recursive) { + foreach (d; dub.project.dependencies.map!(d => d.name).array.sort) { + auto status = this.test(dub, d, app_args, tested_packages); + if (status > 0) return status; + } + } + return 0; } } diff --git a/test/test-recursive.sh b/test/test-recursive.sh new file mode 100755 index 000000000..22029eb0a --- /dev/null +++ b/test/test-recursive.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +. $(dirname "${BASH_SOURCE[0]}")/common.sh + +should_contain () { + for c in ${@:2}; do + if ! { echo $1; } | grep "$c"; then + die $LINENO "$c was not tested." + exit 1 + fi + done +} + +should_not_contain () { + for c in ${@:2}; do + if { echo $1; } | grep "$c"; then + die $LINENO "Unexpected line '$c' was detected." + exit 1 + fi + done +} + +should_contain "$($DUB test -r --root=$(dirname "${BASH_SOURCE[0]}")/test-recursive 2>&1)" "rootPackage" "libraryA" "libraryB" "libraryC" +should_contain "$($DUB test --root=$(dirname "${BASH_SOURCE[0]}")/test-recursive 2>&1)" "rootPackage" +should_not_contain "$($DUB test --root=$(dirname "${BASH_SOURCE[0]}")/test-recursive 2>&1)" "libraryA" "libraryB" "libraryC" diff --git a/test/test-recursive/.no_build b/test/test-recursive/.no_build new file mode 100644 index 000000000..e69de29bb diff --git a/test/test-recursive/.no_run b/test/test-recursive/.no_run new file mode 100644 index 000000000..e69de29bb diff --git a/test/test-recursive/.no_test b/test/test-recursive/.no_test new file mode 100644 index 000000000..e69de29bb diff --git a/test/test-recursive/dub.sdl b/test/test-recursive/dub.sdl new file mode 100644 index 000000000..447527ca9 --- /dev/null +++ b/test/test-recursive/dub.sdl @@ -0,0 +1,4 @@ +name "test-recursive" +dependency "library-a" path="./libraryA" +dependency "library-b" path="./libraryB" +dependency "library-c" path="./libraryC" diff --git a/test/test-recursive/libraryA/dub.sdl b/test/test-recursive/libraryA/dub.sdl new file mode 100644 index 000000000..5bcf35d11 --- /dev/null +++ b/test/test-recursive/libraryA/dub.sdl @@ -0,0 +1,3 @@ +name "library-a" +dependency "library-b" path="../libraryB" +dependency "library-c" path="../libraryC" diff --git a/test/test-recursive/libraryA/source/app.d b/test/test-recursive/libraryA/source/app.d new file mode 100644 index 000000000..692a15841 --- /dev/null +++ b/test/test-recursive/libraryA/source/app.d @@ -0,0 +1,7 @@ +void main() {} + +unittest +{ + import std.stdio : writeln; + writeln("Testing libraryA..."); +} diff --git a/test/test-recursive/libraryB/dub.sdl b/test/test-recursive/libraryB/dub.sdl new file mode 100644 index 000000000..f535b40ae --- /dev/null +++ b/test/test-recursive/libraryB/dub.sdl @@ -0,0 +1,2 @@ +name "library-b" +dependency "library-c" path="../libraryC" diff --git a/test/test-recursive/libraryB/source/app.d b/test/test-recursive/libraryB/source/app.d new file mode 100644 index 000000000..c6de81062 --- /dev/null +++ b/test/test-recursive/libraryB/source/app.d @@ -0,0 +1,7 @@ +void main() {} + +unittest +{ + import std.stdio : writeln; + writeln("Testing libraryB..."); +} diff --git a/test/test-recursive/libraryC/dub.sdl b/test/test-recursive/libraryC/dub.sdl new file mode 100644 index 000000000..24fa42a0c --- /dev/null +++ b/test/test-recursive/libraryC/dub.sdl @@ -0,0 +1 @@ +name "library-c" diff --git a/test/test-recursive/libraryC/source/app.d b/test/test-recursive/libraryC/source/app.d new file mode 100644 index 000000000..29b1290d3 --- /dev/null +++ b/test/test-recursive/libraryC/source/app.d @@ -0,0 +1,7 @@ +void main() {} + +unittest +{ + import std.stdio : writeln; + writeln("Testing libraryC..."); +} diff --git a/test/test-recursive/source/app.d b/test/test-recursive/source/app.d new file mode 100644 index 000000000..48902a179 --- /dev/null +++ b/test/test-recursive/source/app.d @@ -0,0 +1,7 @@ +void main() {} + +unittest +{ + import std.stdio : writeln; + writeln("Testing rootPackage..."); +}