Skip to content

Commit 46da91b

Browse files
Geod24dlang-bot
authored andcommitted
Testsuite: Add more structured paths
So we can start replicating the filesystem in unittests.
1 parent aad10ee commit 46da91b

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

source/dub/test/base.d

+29-7
Original file line numberDiff line numberDiff line change
@@ -123,20 +123,42 @@ public void disableLogging()
123123
* This instance of dub should not read any environment variables,
124124
* nor should it do any file IO, to make it usable and reliable in unittests.
125125
* Currently it reads environment variables but does not read the configuration.
126+
*
127+
* Note that since the design of Dub was centered on the file system for so long,
128+
* `NativePath` is still a core part of how one interacts with this class.
129+
* In order to be as close to the production code as possible, this class
130+
* use the following conventions:
131+
* - The project is located under `/dub/project/`;
132+
* - The user and system packages are under `/dub/user/packages/` and
133+
* `/dub/system/packages/`, respectively;
134+
* Those paths don't need to exists, but they are what one might see
135+
* when writing and debugging unittests.
126136
*/
127137
public class TestDub : Dub
128138
{
139+
/// Convenience constants for use in unittets
140+
public static immutable ProjectPath = "/dub/project/";
141+
/// Ditto
142+
public static immutable SpecialDirs Paths = {
143+
temp: "/dub/temp/",
144+
systemSettings: "/dub/system/",
145+
userSettings: "/dub/user/",
146+
userPackages: "/dub/user/",
147+
cache: "/dub/user/cache/",
148+
};
149+
129150
/// Forward to base constructor
130-
public this (string root = ".", PackageSupplier[] extras = null,
131-
SkipPackageSuppliers skip = SkipPackageSuppliers.none)
151+
public this (string root = ProjectPath,
152+
PackageSupplier[] extras = null,
153+
SkipPackageSuppliers skip = SkipPackageSuppliers.none)
132154
{
133155
super(root, extras, skip);
134156
}
135157

136158
/// Avoid loading user configuration
137159
protected override Settings loadConfig(ref SpecialDirs dirs) const
138160
{
139-
// No-op
161+
dirs = Paths;
140162
return Settings.init;
141163
}
142164

@@ -252,10 +274,10 @@ package class TestPackageManager : PackageManager
252274

253275
this()
254276
{
255-
NativePath pkg = NativePath("/tmp/dub-testsuite-nonexistant/packages/");
256-
NativePath user = NativePath("/tmp/dub-testsuite-nonexistant/user/");
257-
NativePath system = NativePath("/tmp/dub-testsuite-nonexistant/system/");
258-
super(pkg, user, system, false);
277+
NativePath local = NativePath(TestDub.ProjectPath);
278+
NativePath user = TestDub.Paths.userSettings;
279+
NativePath system = TestDub.Paths.systemSettings;
280+
super(local, user, system, false);
259281
}
260282

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

0 commit comments

Comments
 (0)