Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: recursive option on test command #1873

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/recursive-test.dd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Added dependency recursive test

Dub now supports recursive test run. This feature can be activated by option `-r` or `--recursive`.
20 changes: 20 additions & 0 deletions source/dub/commandline.d
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@
bool m_combined = false;
bool m_parallel = false;
bool m_force = false;
bool m_recursive = false;
}

this()
Expand Down Expand Up @@ -1009,6 +1010,9 @@
args.getopt("f|force", &m_force, [
"Forces a recompilation even if the target is up to date"
]);
args.getopt("r|recursive", &m_recursive, [

Check warning on line 1013 in source/dub/commandline.d

View check run for this annotation

Codecov / codecov/patch

source/dub/commandline.d#L1013

Added line #L1013 was not covered by tests
"Runs test including dependent packages."
]);
bool coverage = false;
args.getopt("coverage", &coverage, [
"Enables code coverage statistics to be generated."
Expand All @@ -1024,6 +1028,15 @@
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);

Check warning on line 1032 in source/dub/commandline.d

View check run for this annotation

Codecov / codecov/patch

source/dub/commandline.d#L1031-L1032

Added lines #L1031 - L1032 were not covered by tests
}

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;

Check warning on line 1038 in source/dub/commandline.d

View check run for this annotation

Codecov / codecov/patch

source/dub/commandline.d#L1037-L1038

Added lines #L1037 - L1038 were not covered by tests

setupPackage(dub, package_name, "unittest");

GeneratorSettings settings;
Expand All @@ -1041,6 +1054,13 @@
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;

Check warning on line 1060 in source/dub/commandline.d

View check run for this annotation

Codecov / codecov/patch

source/dub/commandline.d#L1057-L1060

Added lines #L1057 - L1060 were not covered by tests
}
}

return 0;
}
}
Expand Down
25 changes: 25 additions & 0 deletions test/test-recursive.sh
Original file line number Diff line number Diff line change
@@ -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"
Empty file added test/test-recursive/.no_build
Empty file.
Empty file added test/test-recursive/.no_run
Empty file.
Empty file added test/test-recursive/.no_test
Empty file.
4 changes: 4 additions & 0 deletions test/test-recursive/dub.sdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name "test-recursive"
dependency "library-a" path="./libraryA"
dependency "library-b" path="./libraryB"
dependency "library-c" path="./libraryC"
3 changes: 3 additions & 0 deletions test/test-recursive/libraryA/dub.sdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name "library-a"
dependency "library-b" path="../libraryB"
dependency "library-c" path="../libraryC"
7 changes: 7 additions & 0 deletions test/test-recursive/libraryA/source/app.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
void main() {}

unittest
{
import std.stdio : writeln;
writeln("Testing libraryA...");
}
2 changes: 2 additions & 0 deletions test/test-recursive/libraryB/dub.sdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name "library-b"
dependency "library-c" path="../libraryC"
7 changes: 7 additions & 0 deletions test/test-recursive/libraryB/source/app.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
void main() {}

unittest
{
import std.stdio : writeln;
writeln("Testing libraryB...");
}
1 change: 1 addition & 0 deletions test/test-recursive/libraryC/dub.sdl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name "library-c"
7 changes: 7 additions & 0 deletions test/test-recursive/libraryC/source/app.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
void main() {}

unittest
{
import std.stdio : writeln;
writeln("Testing libraryC...");
}
7 changes: 7 additions & 0 deletions test/test-recursive/source/app.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
void main() {}

unittest
{
import std.stdio : writeln;
writeln("Testing rootPackage...");
}