From 2b3ea786a88f0434093d60c1be334bcb11171470 Mon Sep 17 00:00:00 2001 From: Mathias Lang Date: Mon, 12 Feb 2024 01:10:54 +0100 Subject: [PATCH] Tests: Add the ability for TestDub to use an initialized filesystem This way, we can test any kind of crazy conditions found in bug reports, such as the behavior in the face of non-writeable filesystem. --- source/dub/test/base.d | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/source/dub/test/base.d b/source/dub/test/base.d index 1f6207f4d..1c41acc81 100644 --- a/source/dub/test/base.d +++ b/source/dub/test/base.d @@ -164,6 +164,26 @@ public class TestDub : Dub super(root, extras, skip); } + /*************************************************************************** + + Instantiate a new `TestDub` instance with the provided filesystem state + + This exposes the raw virtual filesystem to the user, allowing any kind + of customization to happen: Empty directory, non-writeable ones, etc... + + Params: + dg = Delegate to be called with the filesystem, before `TestDub` + instantiation is performed; + + ***************************************************************************/ + + public this (scope void delegate(scope FSEntry root) dg) + { + this.fs = new FSEntry(); + dg(this.fs); + super(ProjectPath.toNativeString(), null, SkipPackageSuppliers.none); + } + /// Avoid loading user configuration protected override Settings loadConfig(ref SpecialDirs dirs) const {