diff --git a/source/dub/dub.d b/source/dub/dub.d index bcb21bb..fe5efe4 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -337,8 +337,12 @@ return ps; } + // Note: This test rely on the environment, which is not how unittests should work. + // This should be removed / refactored to keep coverage without affecting the env. unittest { + import dub.test.base : TestDub; + scope (exit) environment.remove("DUB_REGISTRY"); auto dub = new TestDub(".", null, SkipPackageSuppliers.configured); assert(dub.packageSuppliers.length == 0); @@ -1458,9 +1462,13 @@ return compilers[0]; } + // This test also relies on the environment and the filesystem, + // as the `makePackageSuppliers` does, and should be refactored. unittest { + import dub.test.base : TestDub; import std.path: buildPath, absolutePath; + auto dub = new TestDub(".", null, SkipPackageSuppliers.configured); immutable olddc = environment.get("DC", null); immutable oldpath = environment.get("PATH", null); @@ -1832,30 +1840,6 @@ } } -/** - * An instance of Dub that does not rely on the environment - * - * This instance of dub should not read any environment variables, - * nor should it do any file IO, to make it usable and reliable in unittests. - * Currently it reads environment variables but does not read the configuration. - */ -version(unittest) package class TestDub : Dub -{ - /// Forward to base constructor - public this (string root = ".", PackageSupplier[] extras = null, - SkipPackageSuppliers skip = SkipPackageSuppliers.none) - { - super(root, extras, skip); - } - - /// Avoid loading user configuration - protected override Settings loadConfig(ref SpecialDirs dirs) const - { - // No-op - return Settings.init; - } -} - package struct SpecialDirs { /// The path where to store temporary files and directory NativePath temp; diff --git a/source/dub/test/base.d b/source/dub/test/base.d new file mode 100644 index 0000000..6f7c7b3 --- /dev/null +++ b/source/dub/test/base.d @@ -0,0 +1,53 @@ +/******************************************************************************* + + Base utilities (types, functions) used in tests + +*******************************************************************************/ + +module dub.test.base; + +version (unittest): + +import dub.data.settings; +public import dub.dependency; +import dub.dub; +import dub.package_; +import dub.packagemanager; +import dub.packagesuppliers.packagesupplier; + +// TODO: Remove and handle logging the same way we handle other IO +import dub.internal.logging; + +public void enableLogging() +{ + setLogLevel(LogLevel.debug_); +} + +public void disableLogging() +{ + setLogLevel(LogLevel.none); +} + +/** + * An instance of Dub that does not rely on the environment + * + * This instance of dub should not read any environment variables, + * nor should it do any file IO, to make it usable and reliable in unittests. + * Currently it reads environment variables but does not read the configuration. + */ +public class TestDub : Dub +{ + /// Forward to base constructor + public this (string root = ".", PackageSupplier[] extras = null, + SkipPackageSuppliers skip = SkipPackageSuppliers.none) + { + super(root, extras, skip); + } + + /// Avoid loading user configuration + protected override Settings loadConfig(ref SpecialDirs dirs) const + { + // No-op + return Settings.init; + } +}