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

Testsuite: Add more structured paths #2777

Merged
merged 1 commit into from
Jan 4, 2024
Merged
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
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
Loading