diff --git a/source/dub/commandline.d b/source/dub/commandline.d index 8d73b6a..45fa3bd 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -1391,6 +1391,7 @@ settings.tempBuild = m_single; settings.run = true; settings.runArgs = app_args; + settings.single = m_single; dub.testProject(settings, m_buildConfig, NativePath(m_mainFile)); return 0; diff --git a/source/dub/dub.d b/source/dub/dub.d index 683996f..c11737b 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -660,13 +660,15 @@ // prepare the list of tested modules string[] import_modules; + if (settings.single) + lbuildsettings.importPaths ~= NativePath(mainfil).parentPath.toNativeString; foreach (file; lbuildsettings.sourceFiles) { if (file.endsWith(".d")) { auto fname = NativePath(file).head.name; NativePath msf = NativePath(mainfil); if (msf.absolute) msf = msf.relativeTo(m_project.rootPackage.path); - if (NativePath(file).relativeTo(m_project.rootPackage.path) == msf) { + if (!settings.single && NativePath(file).relativeTo(m_project.rootPackage.path) == msf) { logWarn("Excluding main source file %s from test.", mainfil); tcinfo.excludedSourceFiles[""] ~= mainfil; continue; diff --git a/source/dub/project.d b/source/dub/project.d index 2f96a8e..c9d11e3 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -653,7 +653,7 @@ if (shallow && pkg !is m_rootPackage) psettings.sourceFiles = null; processVars(dst, this, pkg, psettings, gsettings); - if (psettings.importPaths.empty) + if (!gsettings.single && psettings.importPaths.empty) logWarn(`Package %s (configuration "%s") defines no import paths, use {"importPaths": [...]} or the default package directory structure to fix this.`, pkg.name, configs[pkg.name]); if (psettings.mainSourceFile.empty && pkg is m_rootPackage && psettings.targetType == TargetType.executable) logWarn(`Executable configuration "%s" of package %s defines no main source file, this may cause certain build modes to fail. Add an explicit "mainSourceFile" to the package description to fix this.`, configs[pkg.name], pkg.name); diff --git a/test/issue_2051_running_unittests_from_dub_single_file_packages_fails.d b/test/issue_2051_running_unittests_from_dub_single_file_packages_fails.d index 08a45ad..3769892 100644 --- a/test/issue_2051_running_unittests_from_dub_single_file_packages_fails.d +++ b/test/issue_2051_running_unittests_from_dub_single_file_packages_fails.d @@ -20,24 +20,7 @@ writeln("\t", line); writeln("--- end of dub output"); - enforce(dub.status == 0, "couldn't build the project, see above"); - - return dub.output; -} - -/// check dub output to determine rebuild has not been triggered -auto checkUnittestsResult(string output) -{ - if (output.lineSplitter.any!(a=> a == "All unit tests have been run successfully.")) - { - writeln("\nOk. Unittest passed."); - return 0; - } - else - { - writeln("\nError. Unittests failed."); - return 1; - } + return dub.status; } int main() @@ -47,9 +30,46 @@ dub = buildPath(".", "bin", "dub"); string filename; - // create test_project + // check if the single file package with dependency compiles and runs { - filename = tempDir.buildPath("issue_2051.d"); + filename = tempDir.buildPath("issue2051_success.d"); + auto f = File(filename, "w"); + f.write( +`#!/usr/bin/env dub +/+ dub.sdl: + name "issue2051" + dependency "taggedalgebraic" version="~>0.11.0" ++/ + +version(unittest) {} +else void main() +{ +} + +unittest +{ + import taggedalgebraic; + + static union Base { + int i; + string str; + } + + auto dummy = TaggedAlgebraic!Base(1721); + assert(dummy == 1721); +} +` ); + } + + const rc1 = text(dub, " test --single ", filename).executeCommand; + if (rc1) + writeln("\nError. Unittests failed."); + else + writeln("\nOk. Unittest passed."); + + // Check if dub `test` command runs unittests for single file package + { + filename = tempDir.buildPath("issue2051_fail.d"); auto f = File(filename, "w"); f.write( `#!/usr/bin/env dub @@ -64,13 +84,16 @@ unittest { - auto input = [1721]; - assert(input[0] == 1721); + assert(0); } ` ); } - return text(dub, " test --single ", filename) - .executeCommand - .checkUnittestsResult; + const rc2 = text(dub, " test --single ", filename).executeCommand; + if (rc2) + writeln("\nOk. Unittests failed."); + else + writeln("\nError. Unittest passed."); + + return rc1 | !rc2; } \ No newline at end of file