@@ -299,8 +299,28 @@ public class TestSelectedVersions : SelectedVersions {
299299 */
300300package class TestPackageManager : PackageManager
301301{
302+ // / `loadSCMPackage` will strip some part of the remote / repository,
303+ // / which we need to mimic to provide a usable API.
304+ private struct GitReference {
305+ // /
306+ this (in Repository repo) {
307+ this .remote = repo.remote.chompPrefix(" git+" );
308+ this .ref_ = repo.ref_.chompPrefix(" ~" );
309+ }
310+
311+ // /
312+ this (in string remote, in string gitref) {
313+ this .remote = remote;
314+ this .ref_ = gitref;
315+ }
316+
317+ string remote;
318+ string ref_;
319+ }
320+
321+
302322 // / List of all SCM packages that can be fetched by this instance
303- protected Package[Repository ] scm;
323+ protected string [GitReference ] scm;
304324 // / The virtual filesystem that this PackageManager acts on
305325 protected FSEntry fs;
306326
@@ -314,7 +334,6 @@ package class TestPackageManager : PackageManager
314334 }
315335
316336 // Re-introduce hidden/deprecated overloads
317- public alias loadSCMPackage = PackageManager.loadSCMPackage;
318337 public alias store = PackageManager.store;
319338
320339 // / Disabled as semantic are not implementable unless a virtual FS is created
@@ -394,38 +413,19 @@ package class TestPackageManager : PackageManager
394413 }
395414
396415 /**
397- * Re-Implementation of `loadSCMPackage `.
416+ * Re-Implementation of `gitClone `.
398417 *
399- * The base implementation will do a `git` clone, which we would like to avoid.
400- * Instead, we allow unittests to explicitly define what packages should be
401- * reachable in a given test.
418+ * The base implementation will do a `git` clone, to the file-system.
419+ * We need to mock both the `git` part and the write to the file system.
402420 */
403- public override Package loadSCMPackage (in PackageName name, in Repository repo)
404- {
405- import std.string : chompPrefix;
406-
407- // We're trying to match `loadGitPackage` as much as possible
408- if (! repo.ref_.startsWith(" ~" ) && ! repo.ref_.isGitHash)
409- return null ;
410-
411- string gitReference = repo.ref_.chompPrefix(" ~" );
412- NativePath destination = this .getPackagePath(PlacementLocation.user, name, repo.ref_);
413-
414- foreach (p; getPackageIterator(name.toString()))
415- if (p.path == destination)
416- return p;
417-
418- return this .loadSCMRepository(name, repo);
419- }
420-
421- // / The private part of `loadSCMPackage`
422- protected Package loadSCMRepository (in PackageName name, in Repository repo)
421+ protected override bool gitClone (string remote, string gitref, in NativePath dest)
423422 {
424- if (auto prepo = repo in this .scm) {
425- this .addPackages(this .m_internal.fromPath, * prepo);
426- return * prepo;
423+ if (auto pstr = GitReference(remote, gitref) in this .scm) {
424+ this .fs.mkdir(dest);
425+ this .fs.writeFile(dest ~ " dub.json" , * pstr);
426+ return true ;
427427 }
428- return null ;
428+ return false ;
429429 }
430430
431431 /**
@@ -463,9 +463,9 @@ package class TestPackageManager : PackageManager
463463 }
464464
465465 // / Add a reachable SCM package to this `PackageManager`
466- public void addTestSCMPackage (Repository repo, Package pkg )
466+ public void addTestSCMPackage (in Repository repo, string dub_json )
467467 {
468- this .scm[repo] = pkg ;
468+ this .scm[GitReference( repo) ] = dub_json ;
469469 }
470470
471471 // /
0 commit comments