From 5e6680406f39b2b0b90d8b137285e066cc358d43 Mon Sep 17 00:00:00 2001 From: Ivan Bobev Date: Thu, 15 Jul 2021 23:13:01 +0300 Subject: Add changes required by Nimble lock file support (#12104) Implemented support for Nimble local cache with package directories with a checksum of the package at the end of their names. Now the compiler supports package paths in the form: * /path_to_nimble_cache_dir/pkgs/package_name-1.2.3- FEBADEAEA2345E777F0F6F8433F7F0A52EDD5D1B * /path_to_nimble_cache_dir/pkgs/package_name-#head- 042D4BE2B90ED0672E717D71850ABDB0A2D19CD2 * /path_to_nimble_cache_dir/pkgs/package_name-#branch-name- DBC1F902CB79946E990E38AF51F0BAD36ACFABD9 Related to nim-lang/nimble#127 --- tests/compiler/tnimblecmd.nim | 97 ++++++++++++++++++++++++++++++++----------- tests/stdlib/tsha1.nim | 10 +++++ 2 files changed, 83 insertions(+), 24 deletions(-) (limited to 'tests') diff --git a/tests/compiler/tnimblecmd.nim b/tests/compiler/tnimblecmd.nim index d39179be1..53bce4625 100644 --- a/tests/compiler/tnimblecmd.nim +++ b/tests/compiler/tnimblecmd.nim @@ -1,26 +1,75 @@ -include compiler/[nimblecmd] +include compiler/[nimblecmd], sets proc v(s: string): Version = s.newVersion -# #head is special in the sense that it's assumed to always be newest. -doAssert v"1.0" < v"#head" -doAssert v"1.0" < v"1.1" -doAssert v"1.0.1" < v"1.1" -doAssert v"1" < v"1.1" -doAssert v"#aaaqwe" < v"1.1" # We cannot assume that a branch is newer. -doAssert v"#a111" < v"#head" - -let conf = newConfigRef() -var rr = newStringTable() -addPackage conf, rr, "irc-#a111", unknownLineInfo -addPackage conf, rr, "irc-#head", unknownLineInfo -addPackage conf, rr, "irc-0.1.0", unknownLineInfo -#addPackage conf, rr, "irc", unknownLineInfo -#addPackage conf, rr, "another", unknownLineInfo -addPackage conf, rr, "another-0.1", unknownLineInfo - -addPackage conf, rr, "ab-0.1.3", unknownLineInfo -addPackage conf, rr, "ab-0.1", unknownLineInfo -addPackage conf, rr, "justone-1.0", unknownLineInfo - -doAssert toSeq(rr.chosen) == - @["irc-#head", "ab-0.1.3", "justone-1.0", "another-0.1"] + +proc testVersionsComparison = + # #head is special in the sense that it's assumed to always be newest. + doAssert v"1.0" < v"#head" + doAssert v"1.0" < v"1.1" + doAssert v"1.0.1" < v"1.1" + doAssert v"1" < v"1.1" + doAssert v"#aaaqwe" < v"1.1" # We cannot assume that a branch is newer. + doAssert v"#a111" < v"#head" + +proc testAddPackageWithoutChecksum = + ## For backward compatibility it is not required all packages to have a + ## sha1 checksum at the end of the name of the Nimble cache directory. + ## This way a new compiler will be able to work with an older Nimble. + + let conf = newConfigRef() + var rr: PackageInfo + + addPackage conf, rr, "irc-#a111", unknownLineInfo + addPackage conf, rr, "irc-#head", unknownLineInfo + addPackage conf, rr, "irc-0.1.0", unknownLineInfo + + addPackage conf, rr, "another-0.1", unknownLineInfo + + addPackage conf, rr, "ab-0.1.3", unknownLineInfo + addPackage conf, rr, "ab-0.1", unknownLineInfo + addPackage conf, rr, "justone-1.0", unknownLineInfo + + doAssert toSeq(rr.chosen).toHashSet == + ["irc-#head", "another-0.1", "ab-0.1.3", "justone-1.0"].toHashSet + +proc testAddPackageWithChecksum = + let conf = newConfigRef() + var rr: PackageInfo + + # in the case of packages with the same version, but different checksums for + # now the first one will be chosen + + addPackage conf, rr, "irc-#a111-DBC1F902CB79946E990E38AF51F0BAD36ACFABD9", + unknownLineInfo + addPackage conf, rr, "irc-#head-042D4BE2B90ED0672E717D71850ABDB0A2D19CD1", + unknownLineInfo + addPackage conf, rr, "irc-#head-042D4BE2B90ED0672E717D71850ABDB0A2D19CD2", + unknownLineInfo + addPackage conf, rr, "irc-0.1.0-6EE6DE936B32E82C7DBE526DA3463574F6568FAF", + unknownLineInfo + + addPackage conf, rr, "another-0.1", unknownLineInfo + addPackage conf, rr, "another-0.1-F07EE6040579F0590608A8FD34F5F2D91D859340", + unknownLineInfo + + addPackage conf, rr, "ab-0.1.3-34BC3B72CE46CF5A496D1121CFEA7369385E9EA2", + unknownLineInfo + addPackage conf, rr, "ab-0.1.3-24BC3B72CE46CF5A496D1121CFEA7369385E9EA2", + unknownLineInfo + addPackage conf, rr, "ab-0.1-A3CFFABDC4759F7779D541F5E031AED17169390A", + unknownLineInfo + + # lower case hex digits is also a valid sha1 checksum + addPackage conf, rr, "justone-1.0-f07ee6040579f0590608a8fd34f5f2d91d859340", + unknownLineInfo + + doAssert toSeq(rr.chosen).toHashSet == [ + "irc-#head-042D4BE2B90ED0672E717D71850ABDB0A2D19CD1", + "another-0.1", + "ab-0.1.3-34BC3B72CE46CF5A496D1121CFEA7369385E9EA2", + "justone-1.0-f07ee6040579f0590608a8fd34f5f2d91d859340" + ].toHashSet + +testVersionsComparison() +testAddPackageWithoutChecksum() +testAddPackageWithChecksum() diff --git a/tests/stdlib/tsha1.nim b/tests/stdlib/tsha1.nim index 7e67ccaf6..a20183039 100644 --- a/tests/stdlib/tsha1.nim +++ b/tests/stdlib/tsha1.nim @@ -11,3 +11,13 @@ checkVector("", "da39a3ee5e6b4b0d3255bfef95601890afd80709") checkVector("abc", "a9993e364706816aba3e25717850c26c9cd0d89d") checkVector("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "84983e441c3bd26ebaae4aa1f95129e5e54670f1") + +proc testIsValidSha1Hash = + doAssert not isValidSha1Hash("") + doAssert not isValidSha1Hash("042D4BE2B90ED0672E717D71850ABDB0A2D19CD11") + doAssert not isValidSha1hash("042G4BE2B90ED0672E717D71850ABDB0A2D19CD1") + doAssert isValidSha1Hash("042D4BE2B90ED0672E717D71850ABDB0A2D19CD1") + doAssert isValidSha1Hash("042d4be2b90ed0672e717d71850abdb0a2d19cd1") + doAssert isValidSha1Hash("042d4be2b90ed0672e717D71850ABDB0A2D19CD1") + +testIsValidSha1Hash() -- cgit 1.4.1-2-gfad0