From 1082f7fcb20274c6fa1bae032ced5bf64a15f3f1 Mon Sep 17 00:00:00 2001 From: Mathias Lang Date: Fri, 23 Feb 2024 23:50:53 +0100 Subject: [PATCH] Test that `add-path` packages take priority This was not currently tested explicitly, and is currently the reason why we still have the scanning behavior in the PackageManager. In order to remove the scanning behavior and have the PM lazily scan packages, we first must add test to ensure there will be no further regression. --- source/dub/test/other.d | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/source/dub/test/other.d b/source/dub/test/other.d index ba74de53d..241fb0f09 100644 --- a/source/dub/test/other.d +++ b/source/dub/test/other.d @@ -46,3 +46,36 @@ unittest assert(dub.project.hasAllDependencies()); assert(dub.project.getDependency("dep1", true), "Missing 'dep1' dependency"); } + +// Test for https://github.com/dlang/dub/pull/2481 +// Make sure packages found with `add-path` take priority. +unittest +{ + const AddPathDir = TestDub.Paths.temp ~ "addpath/"; + const BDir = AddPathDir ~ "b/"; + scope dub = new TestDub((scope FSEntry root) { + root.writeFile(TestDub.ProjectPath ~ "dub.json", + `{ "name": "a", "dependencies": { "b": "~>1.0" } }`); + + root.writePackageFile("b", "1.0.0", `name "b" +version "1.0.0"`, PackageFormat.sdl); + root.mkdir(BDir); + root.writeFile(BDir ~ "dub.json", `{"name": "b", "version": "1.0.0" }`); + }); + + dub.loadPackage(); + assert(!dub.project.hasAllDependencies()); + dub.upgrade(UpgradeOptions.select); + // Test that without add-path, we get a package in the userPackage + const oldDir = dub.project.getDependency("b", true).path(); + assert(oldDir == TestDub.Paths.userPackages ~ "packages/b/1.0.0/b/", + oldDir.toNativeString()); + // Now run `add-path` + dub.addSearchPath(AddPathDir.toNativeString(), dub.defaultPlacementLocation); + // We need a new instance to test + scope newDub = dub.newTest(); + newDub.loadPackage(); + assert(newDub.project.hasAllDependencies()); + const actualDir = newDub.project.getDependency("b", true).path(); + assert(actualDir == BDir, actualDir.toNativeString()); +}