tnimblecmd.nim 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. include compiler/[nimblecmd], sets
  2. proc v(s: string): Version = s.newVersion
  3. proc testVersionsComparison =
  4. # #head is special in the sense that it's assumed to always be newest.
  5. doAssert v"1.0" < v"#head"
  6. doAssert v"1.0" < v"1.1"
  7. doAssert v"1.0.1" < v"1.1"
  8. doAssert v"1" < v"1.1"
  9. doAssert v"#aaaqwe" < v"1.1" # We cannot assume that a branch is newer.
  10. doAssert v"#a111" < v"#head"
  11. proc testAddPackageWithoutChecksum =
  12. ## For backward compatibility it is not required all packages to have a
  13. ## sha1 checksum at the end of the name of the Nimble cache directory.
  14. ## This way a new compiler will be able to work with an older Nimble.
  15. let conf = newConfigRef()
  16. var rr: PackageInfo
  17. addPackage conf, rr, "irc-#a111", unknownLineInfo
  18. addPackage conf, rr, "irc-#head", unknownLineInfo
  19. addPackage conf, rr, "irc-0.1.0", unknownLineInfo
  20. addPackage conf, rr, "another-0.1", unknownLineInfo
  21. addPackage conf, rr, "ab-0.1.3", unknownLineInfo
  22. addPackage conf, rr, "ab-0.1", unknownLineInfo
  23. addPackage conf, rr, "justone-1.0", unknownLineInfo
  24. doAssert toSeq(rr.chosen).toHashSet ==
  25. ["irc-#head", "another-0.1", "ab-0.1.3", "justone-1.0"].toHashSet
  26. proc testAddPackageWithChecksum =
  27. let conf = newConfigRef()
  28. var rr: PackageInfo
  29. # in the case of packages with the same version, but different checksums for
  30. # now the first one will be chosen
  31. addPackage conf, rr, "irc-#a111-DBC1F902CB79946E990E38AF51F0BAD36ACFABD9",
  32. unknownLineInfo
  33. addPackage conf, rr, "irc-#head-042D4BE2B90ED0672E717D71850ABDB0A2D19CD1",
  34. unknownLineInfo
  35. addPackage conf, rr, "irc-#head-042D4BE2B90ED0672E717D71850ABDB0A2D19CD2",
  36. unknownLineInfo
  37. addPackage conf, rr, "irc-0.1.0-6EE6DE936B32E82C7DBE526DA3463574F6568FAF",
  38. unknownLineInfo
  39. addPackage conf, rr, "another-0.1", unknownLineInfo
  40. addPackage conf, rr, "another-0.1-F07EE6040579F0590608A8FD34F5F2D91D859340",
  41. unknownLineInfo
  42. addPackage conf, rr, "ab-0.1.3-34BC3B72CE46CF5A496D1121CFEA7369385E9EA2",
  43. unknownLineInfo
  44. addPackage conf, rr, "ab-0.1.3-24BC3B72CE46CF5A496D1121CFEA7369385E9EA2",
  45. unknownLineInfo
  46. addPackage conf, rr, "ab-0.1-A3CFFABDC4759F7779D541F5E031AED17169390A",
  47. unknownLineInfo
  48. # lower case hex digits is also a valid sha1 checksum
  49. addPackage conf, rr, "justone-1.0-f07ee6040579f0590608a8fd34f5f2d91d859340",
  50. unknownLineInfo
  51. doAssert toSeq(rr.chosen).toHashSet == [
  52. "irc-#head-042D4BE2B90ED0672E717D71850ABDB0A2D19CD1",
  53. "another-0.1",
  54. "ab-0.1.3-34BC3B72CE46CF5A496D1121CFEA7369385E9EA2",
  55. "justone-1.0-f07ee6040579f0590608a8fd34f5f2d91d859340"
  56. ].toHashSet
  57. testVersionsComparison()
  58. testAddPackageWithoutChecksum()
  59. testAddPackageWithChecksum()