Newer
Older
dub_jkp / source / dub / test / other.d
  1. /*******************************************************************************
  2.  
  3. Tests that don't fit in existing categories
  4.  
  5. *******************************************************************************/
  6.  
  7. module dub.test.others;
  8.  
  9. version (unittest):
  10.  
  11. import std.algorithm;
  12. import std.format;
  13. import dub.test.base;
  14.  
  15. // https://github.com/dlang/dub/issues/2696
  16. unittest
  17. {
  18. const ValidURL = `git+https://example.com/dlang/dub`;
  19. // Taken from a commit in the dub repository
  20. const ValidHash = "54339dff7ce9ec24eda550f8055354f712f15800";
  21. const Template = `{"name": "%s", "version": "1.0.0", "dependencies": {
  22. "dep1": { "repository": "%s", "version": "%s" }}}`;
  23.  
  24. scope dub = new TestDub((scope FSEntry fs) {
  25. // Invalid URL, valid hash
  26. fs.writePackageFile("a", "1.0.0", Template.format("a", "git+https://nope.nope", ValidHash));
  27. // Valid URL, invalid hash
  28. fs.writePackageFile("b", "1.0.0", Template.format("b", ValidURL, "invalid"));
  29. // Valid URL, valid hash
  30. fs.writePackageFile("c", "1.0.0", Template.format("c", ValidURL, ValidHash));
  31. });
  32. dub.packageManager.addTestSCMPackage(
  33. Repository(ValidURL, ValidHash), `{ "name": "dep1" }`);
  34.  
  35. try
  36. dub.loadPackage(dub.packageManager.getPackage(PackageName("a"), Version("1.0.0")));
  37. catch (Exception exc)
  38. assert(exc.message.canFind("Unable to fetch"));
  39.  
  40. try
  41. dub.loadPackage(dub.packageManager.getPackage(PackageName("b"), Version("1.0.0")));
  42. catch (Exception exc)
  43. assert(exc.message.canFind("Unable to fetch"));
  44.  
  45. dub.loadPackage(dub.packageManager.getPackage(PackageName("c"), Version("1.0.0")));
  46. assert(dub.project.hasAllDependencies());
  47. assert(dub.project.getDependency("dep1", true), "Missing 'dep1' dependency");
  48. }
  49.  
  50. // Test for https://github.com/dlang/dub/pull/2481
  51. // Make sure packages found with `add-path` take priority.
  52. unittest
  53. {
  54. const AddPathDir = TestDub.Paths.temp ~ "addpath/";
  55. const BDir = AddPathDir ~ "b/";
  56. scope dub = new TestDub((scope FSEntry root) {
  57. root.writeFile(TestDub.ProjectPath ~ "dub.json",
  58. `{ "name": "a", "dependencies": { "b": "~>1.0" } }`);
  59.  
  60. root.writePackageFile("b", "1.0.0", `name "b"
  61. version "1.0.0"`, PackageFormat.sdl);
  62. root.mkdir(BDir);
  63. root.writeFile(BDir ~ "dub.json", `{"name": "b", "version": "1.0.0" }`);
  64. });
  65.  
  66. dub.loadPackage();
  67. assert(!dub.project.hasAllDependencies());
  68. dub.upgrade(UpgradeOptions.select);
  69. // Test that without add-path, we get a package in the userPackage
  70. const oldDir = dub.project.getDependency("b", true).path();
  71. assert(oldDir == TestDub.Paths.userPackages ~ "packages/b/1.0.0/b/",
  72. oldDir.toNativeString());
  73. // Now run `add-path`
  74. dub.addSearchPath(AddPathDir.toNativeString(), dub.defaultPlacementLocation);
  75. // We need a new instance to test
  76. scope newDub = dub.newTest();
  77. newDub.loadPackage();
  78. assert(newDub.project.hasAllDependencies());
  79. const actualDir = newDub.project.getDependency("b", true).path();
  80. assert(actualDir == BDir, actualDir.toNativeString());
  81. }