diff --git a/changelog/build_unittest.dd b/changelog/build_unittest.dd index 13825b8..2574c29 100644 --- a/changelog/build_unittest.dd +++ b/changelog/build_unittest.dd @@ -3,3 +3,6 @@ `dub build --config=unittest --build=unittest[-cov]` can now be used to mimic building the test runner executable of `dub test [--coverage]`. Note that this doesn't require an existing `unittest` configuration. + +`dub describe --config=unittest` allows to derive the path to the +executable. diff --git a/source/dub/commandline.d b/source/dub/commandline.d index 81d054d..fcb0f55 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -1604,6 +1604,14 @@ settings.compiler = m_compiler; settings.filterVersions = m_filterVersions; settings.buildSettings.options |= m_buildSettings.options & BuildOption.lowmem; + settings.single = m_single; + + // With a requested `unittest` config, switch to the special test runner + // config (which doesn't require an existing `unittest` configuration). + if (config == "unittest") { + const test_config = dub.project.addTestRunnerConfiguration(settings, false); + if (test_config) settings.config = test_config; + } if (m_importPaths) { m_data = ["import-paths"]; m_dataList = true; } else if (m_stringImportPaths) { m_data = ["string-import-paths"]; m_dataList = true; } diff --git a/test/issue1856-build-unittest.sh b/test/issue1856-build-unittest.sh index 7db7f1c..d090092 100755 --- a/test/issue1856-build-unittest.sh +++ b/test/issue1856-build-unittest.sh @@ -17,7 +17,8 @@ +/ void foo() {} EOF -$DUB build --single "$TMPDIR/no_ut.d" --config=unittest --build=unittest +$DUB describe --single "$TMPDIR/no_ut.d" --config=unittest | grep -q '"targetName": "no_ut-test-library"' +$DUB build --single "$TMPDIR/no_ut.d" --config=unittest --build=unittest "$TMPDIR/no_ut-test-library" # partial unittest config @@ -31,7 +32,8 @@ +/ void foo() {} EOF -$DUB build --single "$TMPDIR/partial_ut.d" --config=unittest --build=unittest +$DUB describe --single "$TMPDIR/partial_ut.d" --config=unittest | grep -q '"targetName": "partial_ut-test-unittest"' +$DUB build --single "$TMPDIR/partial_ut.d" --config=unittest --build=unittest "$TMPDIR/bin/partial_ut-test-unittest" # full unittest config @@ -46,5 +48,6 @@ +/ void main() {} EOF -$DUB build --single "$TMPDIR/full_ut.d" --config=unittest --build=unittest +$DUB describe --single "$TMPDIR/full_ut.d" --config=unittest | grep -q '"targetName": "full_ut"' +$DUB build --single "$TMPDIR/full_ut.d" --config=unittest --build=unittest "$TMPDIR/bin/full_ut"