Skip to content

Commit

Permalink
Testsuite: Add more structured paths
Browse files Browse the repository at this point in the history
So we can start replicating the filesystem in unittests.
  • Loading branch information
Geod24 authored and dlang-bot committed Jan 4, 2024
1 parent aad10ee commit 46da91b
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions source/dub/test/base.d
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,42 @@ public void disableLogging()
* 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.
*
* Note that since the design of Dub was centered on the file system for so long,
* `NativePath` is still a core part of how one interacts with this class.
* In order to be as close to the production code as possible, this class
* use the following conventions:
* - The project is located under `/dub/project/`;
* - The user and system packages are under `/dub/user/packages/` and
* `/dub/system/packages/`, respectively;
* Those paths don't need to exists, but they are what one might see
* when writing and debugging unittests.
*/
public class TestDub : Dub
{
/// Convenience constants for use in unittets
public static immutable ProjectPath = "/dub/project/";
/// Ditto
public static immutable SpecialDirs Paths = {
temp: "/dub/temp/",
systemSettings: "/dub/system/",
userSettings: "/dub/user/",
userPackages: "/dub/user/",
cache: "/dub/user/cache/",
};

/// Forward to base constructor
public this (string root = ".", PackageSupplier[] extras = null,
SkipPackageSuppliers skip = SkipPackageSuppliers.none)
public this (string root = ProjectPath,
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
dirs = Paths;
return Settings.init;
}

Expand Down Expand Up @@ -252,10 +274,10 @@ package class TestPackageManager : PackageManager

this()
{
NativePath pkg = NativePath("/tmp/dub-testsuite-nonexistant/packages/");
NativePath user = NativePath("/tmp/dub-testsuite-nonexistant/user/");
NativePath system = NativePath("/tmp/dub-testsuite-nonexistant/system/");
super(pkg, user, system, false);
NativePath local = NativePath(TestDub.ProjectPath);
NativePath user = TestDub.Paths.userSettings;
NativePath system = TestDub.Paths.systemSettings;
super(local, user, system, false);
}

/// Disabled as semantic are not implementable unless a virtual FS is created
Expand Down

0 comments on commit 46da91b

Please sign in to comment.