diff --git a/src/nimblepkg/download.nim b/src/nimblepkg/download.nim index 8eb47ae0..703ca0ba 100644 --- a/src/nimblepkg/download.nim +++ b/src/nimblepkg/download.nim @@ -1,23 +1,21 @@ # Copyright (C) Dominik Picheta. All rights reserved. # BSD License. Look at license.txt for more info. -import parseutils, os, osproc, strutils, tables, uri, strformat, - httpclient, json, sequtils, urls +import + parseutils, os, osproc, strutils, tables, uri, strformat, httpclient, json, sequtils, + urls from algorithm import SortOrder, sorted -import packageinfotypes, packageparser, version, tools, common, options, cli, - sha1hashes, vcstools, displaymessages, packageinfo, config, declarativeparser, packagemetadatafile +import + packageinfotypes, packageparser, version, tools, common, options, cli, sha1hashes, + vcstools, displaymessages, packageinfo, config, declarativeparser, packagemetadatafile -type - DownloadPkgResult* = tuple - dir: string - version: Version - vcsRevision: Sha1Hash +type DownloadPkgResult* = tuple[dir: string, version: Version, vcsRevision: Sha1Hash] proc updateSubmodules(dir: string) = - discard tryDoCmdEx( - &"git -C {dir.quoteShell} submodule update --init --recursive --depth 1") + discard + tryDoCmdEx(&"git -C {dir.quoteShell} submodule update --init --recursive --depth 1") proc doCheckout*(meth: DownloadMethod, downloadDir, branch: string, options: Options) = case meth @@ -31,33 +29,48 @@ proc doCheckout*(meth: DownloadMethod, downloadDir, branch: string, options: Opt of DownloadMethod.hg: discard tryDoCmdEx(&"hg --cwd {downloadDir.quoteShell} checkout {branch}") -proc doClone(meth: DownloadMethod, url, downloadDir: string, branch = "", - onlyTip = true, options: Options) = +proc doClone( + meth: DownloadMethod, + url, downloadDir: string, + branch = "", + onlyTip = true, + options: Options, +) = case meth of DownloadMethod.git: let submoduleFlag = if not options.ignoreSubmodules: " --recurse-submodules" else: "" depthArg = if onlyTip: "--depth 1" else: "" - branchArg = if branch == "": "" else: &"-b {branch}" + branchArg = + if branch == "": + "" + else: + &"-b {branch}" discard tryDoCmdEx( - "git clone --config core.autocrlf=false --config core.eol=lf " & - &"{submoduleFlag} {depthArg} {branchArg} {url} {downloadDir.quoteShell}") + "git clone --config core.autocrlf=false --config core.eol=lf " & + &"{submoduleFlag} {depthArg} {branchArg} {url} {downloadDir.quoteShell}" + ) if not options.ignoreSubmodules: downloadDir.updateSubmodules of DownloadMethod.hg: let tipArg = if onlyTip: "-r tip " else: "" - branchArg = if branch == "": "" else: &"-b {branch}" + branchArg = + if branch == "": + "" + else: + &"-b {branch}" discard tryDoCmdEx(&"hg clone {tipArg} {branchArg} {url} {downloadDir.quoteShell}") proc gitFetchTags*(repoDir: string, downloadMethod: DownloadMethod, options: Options) = - case downloadMethod: - of DownloadMethod.git: - let submoduleFlag = if not options.ignoreSubmodules: " --recurse-submodules" else: "" - tryDoCmdEx(&"git -C {repoDir} fetch --tags" & submoduleFlag) - of DownloadMethod.hg: - # In Mercurial, pulling updates also fetches all remote tags - tryDoCmdEx(&"hg --cwd {repoDir} pull") + case downloadMethod + of DownloadMethod.git: + let submoduleFlag = + if not options.ignoreSubmodules: " --recurse-submodules" else: "" + tryDoCmdEx(&"git -C {repoDir} fetch --tags" & submoduleFlag) + of DownloadMethod.hg: + # In Mercurial, pulling updates also fetches all remote tags + tryDoCmdEx(&"hg --cwd {repoDir} pull") proc getTagsList*(dir: string, meth: DownloadMethod): seq[string] = var output: string @@ -72,12 +85,14 @@ proc getTagsList*(dir: string, meth: DownloadMethod): seq[string] = of DownloadMethod.git: result = @[] for i in output.splitLines(): - if i == "": continue + if i == "": + continue result.add(i) of DownloadMethod.hg: result = @[] for i in output.splitLines(): - if i == "": continue + if i == "": + continue var tag = "" discard parseUntil(i, tag, ' ') if tag != "tip": @@ -91,16 +106,18 @@ proc getTagsListRemote*(url: string, meth: DownloadMethod): seq[string] = of DownloadMethod.git: var (output, exitCode) = doCmdEx(&"git ls-remote --tags {url}") if exitCode != QuitSuccess: - raise nimbleError("Unable to query remote tags for " & url & - " . Git returned: " & output) + raise nimbleError( + "Unable to query remote tags for " & url & " . Git returned: " & output + ) for i in output.splitLines(): let refStart = i.find("refs/tags/") # git outputs warnings, empty lines, etc - if refStart == -1: continue - let start = refStart+"refs/tags/".len - let tag = i[start .. i.len-1] - if not tag.endswith("^{}"): result.add(tag) - + if refStart == -1: + continue + let start = refStart + "refs/tags/".len + let tag = i[start .. i.len - 1] + if not tag.endswith("^{}"): + result.add(tag) of DownloadMethod.hg: # http://stackoverflow.com/questions/2039150/show-tags-for-remote-hg-repository raise nimbleError("Hg doesn't support remote tag querying.") @@ -108,25 +125,31 @@ proc getTagsListRemote*(url: string, meth: DownloadMethod): seq[string] = proc getVersionList*(tags: seq[string]): OrderedTable[Version, string] = ## Return an ordered table of Version -> git tag label. Ordering is ## in descending order with the most recent version first. - let taggedVers: seq[tuple[ver: Version, tag: string]] = - tags - .filterIt(it != "") - .map(proc(s: string): tuple[ver: Version, tag: string] = + let taggedVers: seq[tuple[ver: Version, tag: string]] = tags + .filterIt(it != "") + .map( + proc(s: string): tuple[ver: Version, tag: string] = # skip any chars before the version let i = skipUntil(s, Digits) # TODO: Better checking, tags can have any # names. Add warnings and such. - result = (newVersion(s[i .. s.len-1]), s)) - .sorted(proc(a, b: (Version, string)): int = cmp(a[0], b[0]), - SortOrder.Descending) + result = (newVersion(s[i .. s.len - 1]), s) + ) + .sorted( + proc(a, b: (Version, string)): int = + cmp(a[0], b[0]), + SortOrder.Descending, + ) result = toOrderedTable[Version, string](taggedVers) proc getHeadName*(meth: DownloadMethod): Version = ## Returns the name of the download method specific head. i.e. for git ## it's ``head`` for hg it's ``tip``. case meth - of DownloadMethod.git: newVersion("#head") - of DownloadMethod.hg: newVersion("#tip") + of DownloadMethod.git: + newVersion("#head") + of DownloadMethod.hg: + newVersion("#tip") proc checkUrlType*(url: string): DownloadMethod = ## Determines the download method based on the URL. @@ -147,9 +170,12 @@ proc getUrlData*(url: string): (string, Table[string, string]) = uri.query = "" return ($uri, {"subdir": subdir}.toTable()) -proc cloneSpecificRevision(downloadMethod: DownloadMethod, - url, downloadDir: string, - vcsRevision: Sha1Hash, options: Options) = +proc cloneSpecificRevision( + downloadMethod: DownloadMethod, + url, downloadDir: string, + vcsRevision: Sha1Hash, + options: Options, +) = assert vcsRevision != notSetSha1Hash display("Cloning", "revision: " & $vcsRevision, priority = MediumPriority) @@ -161,14 +187,15 @@ proc cloneSpecificRevision(downloadMethod: DownloadMethod, discard tryDoCmdEx(&"git -C {downloadDir.quoteShell} config core.autocrlf false") discard tryDoCmdEx(&"git -C {downloadDir.quoteShell} remote add origin {url}") discard tryDoCmdEx( - &"git -C {downloadDir.quoteShell} fetch --depth 1 origin {vcsRevision}") + &"git -C {downloadDir.quoteShell} fetch --depth 1 origin {vcsRevision}" + ) discard tryDoCmdEx(&"git -C {downloadDir.quoteShell} reset --hard FETCH_HEAD") if not options.ignoreSubmodules: downloadDir.updateSubmodules of DownloadMethod.hg: discard tryDoCmdEx(&"hg clone {url} -r {vcsRevision}") -proc getTarExePath: string = +proc getTarExePath(): string = ## Returns path to `tar` executable. var tarExePath {.global.}: string once: @@ -180,7 +207,7 @@ proc getTarExePath: string = tarExePath = tarExePath.quoteShell return tarExePath -proc hasTar: bool = +proc hasTar(): bool = ## Checks whether a `tar` external tool is available. var hasTar {.global.} = false once: @@ -199,18 +226,18 @@ proc isGitHubRepo(url: string): bool = proc downloadTarball(url: string, options: Options): bool = ## Determines whether to download the repository as a tarball. ## Tarballs don't include git submodules, so we must use git clone when submodules are needed. - options.enableTarballs and - not options.forceFullClone and - url.isGitHubRepo and - hasTar() and - options.ignoreSubmodules # Only use tarballs when ignoring submodules + options.enableTarballs and not options.forceFullClone and url.isGitHubRepo and hasTar() and + options.ignoreSubmodules # Only use tarballs when ignoring submodules proc removeTrailingGitString*(url: string): string = ## Removes ".git" from an URL. ## ## For example: ## "https://github.com/nim-lang/nimble.git" -> "https://github.com/nim-lang/nimble" - if url.len > 4 and url.endsWith(".git"): url[0..^5] else: url + if url.len > 4 and url.endsWith(".git"): + url[0 ..^ 5] + else: + url proc getTarballDownloadLink(url, version: string): string = ## Returns the package tarball download link for given repository URL and @@ -253,7 +280,7 @@ proc getFullRevisionFromGitHubApi(url, version: string): Sha1Hash = ## the full hash of the commit by using GitHub REST API. try: let gitHubApiUrl = getGitHubApiUrl(url, version) - display("Get", gitHubApiUrl); + display("Get", gitHubApiUrl) let content = getUrlContent(gitHubApiUrl) let json = parseJson(content) if json.hasKey("sha"): @@ -261,8 +288,11 @@ proc getFullRevisionFromGitHubApi(url, version: string): Sha1Hash = else: raise nimbleError(json["message"].str) except CatchableError as error: - raise nimbleError(&"Cannot get revision for version \"{version}\" " & - &"of package at \"{url}\".", details = error) + raise nimbleError( + &"Cannot get revision for version \"{version}\" " & &"of package at \"{url}\".", + details = error, + ) + {.warning[ProveInit]: on.} proc parseRevision(lsRemoteOutput: string): Sha1Hash = @@ -273,7 +303,7 @@ proc parseRevision(lsRemoteOutput: string): Sha1Hash = for line in lines: if line.len >= 40: try: - return line[0..39].initSha1Hash + return line[0 .. 39].initSha1Hash except InvalidSha1HashError: discard return notSetSha1Hash @@ -287,8 +317,9 @@ proc getRevision(url, version: string): Sha1Hash = if version.seemsLikeRevision: result = getFullRevisionFromGitHubApi(url, version) else: - raise nimbleError(&"Cannot get revision for version \"{version}\" " & - &"of package at \"{url}\".") + raise nimbleError( + &"Cannot get revision for version \"{version}\" " & &"of package at \"{url}\"." + ) proc getTarCmdLine(downloadDir, filePath: string): string = ## Returns an OS specific command and arguments for extracting the downloaded @@ -297,12 +328,13 @@ proc getTarCmdLine(downloadDir, filePath: string): string = let downloadDir = downloadDir.replace('\\', '/') let filePath = filePath.replace('\\', '/') &"{getTarExePath()} -C {downloadDir.quoteShell} -xf {filePath} --strip-components 1 " & - "--force-local" + "--force-local" else: &"tar -C {downloadDir.quoteShell} -xf {filePath} --strip-components 1" -proc doDownloadTarball(url, downloadDir, version: string, queryRevision: bool): - Sha1Hash = +proc doDownloadTarball( + url, downloadDir, version: string, queryRevision: bool +): Sha1Hash = ## Downloads package tarball from GitHub. Returns the commit hash of the ## downloaded package in the case `queryRevision` is `true`. @@ -349,13 +381,20 @@ proc doDownloadTarball(url, downloadDir, version: string, queryRevision: bool): writeFile(downloadDir / linkName, linkPath) filePath.removeFile - return if queryRevision: getRevision(url, version) else: notSetSha1Hash + return + if queryRevision: + getRevision(url, version) + else: + notSetSha1Hash {.warning[ProveInit]: off.} -proc doDownload(url, downloadDir: string, verRange: VersionRange, - downMethod: DownloadMethod, options: Options, - vcsRevision: Sha1Hash): - tuple[version: Version, vcsRevision: Sha1Hash] = +proc doDownload( + url, downloadDir: string, + verRange: VersionRange, + downMethod: DownloadMethod, + options: Options, + vcsRevision: Sha1Hash, +): tuple[version: Version, vcsRevision: Sha1Hash] = ## Downloads the repository specified by ``url`` using the specified download ## method. ## @@ -384,20 +423,22 @@ proc doDownload(url, downloadDir: string, verRange: VersionRange, result.vcsRevision = vcsRevision elif verRange.kind == verSpecial: # We want a specific commit/branch/tag here. - if verRange.spe == getHeadName(downMethod): - # Grab HEAD. + if verRange.spe == getHeadName(downMethod): # Grab HEAD. if downloadTarball(url, options): result.vcsRevision = doDownloadTarball(url, downloadDir, "HEAD", true) else: - doClone(downMethod, url, downloadDir, - onlyTip = not options.forceFullClone, options = options) + doClone( + downMethod, + url, + downloadDir, + onlyTip = not options.forceFullClone, + options = options, + ) else: - assert ($verRange.spe)[0] == '#', - "The special version must start with '#'." + assert ($verRange.spe)[0] == '#', "The special version must start with '#'." let specialVersion = substr($verRange.spe, 1) if downloadTarball(url, options): - result.vcsRevision = doDownloadTarball( - url, downloadDir, specialVersion, true) + result.vcsRevision = doDownloadTarball(url, downloadDir, specialVersion, true) else: # Grab the full repo. doClone(downMethod, url, downloadDir, onlyTip = false, options = options) @@ -415,58 +456,90 @@ proc doDownload(url, downloadDir: string, verRange: VersionRange, if versions.len > 0: getLatestByTag: if downloadTarball(url, options): - let versionToDownload = - if latest.tag.len > 0: latest.tag else: "HEAD" - result.vcsRevision = doDownloadTarball( - url, downloadDir, versionToDownload, true) + let versionToDownload = if latest.tag.len > 0: latest.tag else: "HEAD" + result.vcsRevision = + doDownloadTarball(url, downloadDir, versionToDownload, true) else: - display("Cloning", "latest tagged version: " & latest.tag, - priority = MediumPriority) - doClone(downMethod, url, downloadDir, latest.tag, - onlyTip = not options.forceFullClone, options = options) + display( + "Cloning", + "latest tagged version: " & latest.tag, + priority = MediumPriority, + ) + doClone( + downMethod, + url, + downloadDir, + latest.tag, + onlyTip = not options.forceFullClone, + options = options, + ) else: - display("Warning:", "The package has no tagged releases, downloading HEAD instead.", Warning, - priority = HighPriority) + display( + "Warning:", + "Package from '" & url & "' has no tagged releases, downloading HEAD instead.", + Warning, + priority = HighPriority, + ) if downloadTarball(url, options): result.vcsRevision = doDownloadTarball(url, downloadDir, "HEAD", true) else: # If no commits have been tagged on the repo we just clone HEAD. - doClone(downMethod, url, downloadDir, onlyTip = not options.forceFullClone, options = options) # Grab HEAD. + doClone( + downMethod, + url, + downloadDir, + onlyTip = not options.forceFullClone, + options = options, + ) # Grab HEAD. of DownloadMethod.hg: - doClone(downMethod, url, downloadDir, - onlyTip = not options.forceFullClone, options = options) + doClone( + downMethod, + url, + downloadDir, + onlyTip = not options.forceFullClone, + options = options, + ) result.version = getHeadName(downMethod) let versions = getTagsList(downloadDir, downMethod).getVersionList() if versions.len > 0: getLatestByTag: - display("Switching", "to latest tagged version: " & latest.tag, - priority = MediumPriority) + display( + "Switching", + "to latest tagged version: " & latest.tag, + priority = MediumPriority, + ) doCheckout(downMethod, downloadDir, latest.tag, options = options) else: - display("Warning:", "The package has no tagged releases, downloading HEAD instead.", Warning, - priority = HighPriority) + display( + "Warning:", + "Package from '" & url & "' has no tagged releases, downloading HEAD instead.", + Warning, + priority = HighPriority, + ) if result.vcsRevision == notSetSha1Hash: # In the case the package in not downloaded as tarball we must query its # VCS revision from its download directory. result.vcsRevision = downloadDir.getVcsRevision + {.warning[ProveInit]: on.} proc pkgDirHasNimble*(dir: string, options: Options): bool = try: discard findNimbleFile(dir, true, options) return true - except NimbleError: + except NimbleError: #Continue with the download discard -proc downloadPkgDir*(url: string, - verRange: VersionRange, - subdir: string, - options: Options, - vcsRevision: Sha1Hash = notSetSha1Hash, - downloadPath: string = "" +proc downloadPkgDir*( + url: string, + verRange: VersionRange, + subdir: string, + options: Options, + vcsRevision: Sha1Hash = notSetSha1Hash, + downloadPath: string = "", ): (string, string) = let downloadDir = if downloadPath == "": @@ -478,13 +551,16 @@ proc downloadPkgDir*(url: string, result = (downloadDir, downloadDir / subdir) -proc downloadPkg*(url: string, verRange: VersionRange, - downMethod: DownloadMethod, - subdir: string, - options: Options, - downloadPath: string, - vcsRevision: Sha1Hash, - validateRange = true): DownloadPkgResult = +proc downloadPkg*( + url: string, + verRange: VersionRange, + downMethod: DownloadMethod, + subdir: string, + options: Options, + downloadPath: string, + vcsRevision: Sha1Hash, + validateRange = true, +): DownloadPkgResult = ## Downloads the repository as specified by ``url`` and ``verRange`` using ## the download method specified. ## @@ -497,7 +573,8 @@ proc downloadPkg*(url: string, verRange: VersionRange, ## If specified this parameter will cause specific VCS revision to be ## checked out. - let (downloadDir, pkgDir) = downloadPkgDir(url, verRange, subdir, options, vcsRevision, downloadPath) + let (downloadDir, pkgDir) = + downloadPkgDir(url, verRange, subdir, options, vcsRevision, downloadPath) result.dir = pkgDir #when using a persistent download dir we can skip the download if it's already done @@ -509,20 +586,26 @@ proc downloadPkg*(url: string, verRange: VersionRange, let modUrl = modifyUrl(url, options.config.cloneUsingHttps) - let downloadMethod = if downloadTarball(modUrl, options): - "http" else: $downMethod + let downloadMethod = + if downloadTarball(modUrl, options): + "http" + else: + $downMethod if subdir.len > 0: - display("Downloading", "$1 using $2 (subdir is '$3')" % - [modUrl, downloadMethod, subdir], - priority = HighPriority) + display( + "Downloading", + "$1 using $2 (subdir is '$3')" % [modUrl, downloadMethod, subdir], + priority = HighPriority, + ) else: - display("Downloading", "$1 using $2" % [modUrl, downloadMethod], - priority = HighPriority) + display( + "Downloading", "$1 using $2" % [modUrl, downloadMethod], priority = HighPriority + ) + + (result.version, result.vcsRevision) = + doDownload(modUrl, downloadDir, verRange, downMethod, options, vcsRevision) - (result.version, result.vcsRevision) = doDownload( - modUrl, downloadDir, verRange, downMethod, options, vcsRevision) - var metaData = initPackageMetaData() metaData.url = modUrl metaData.vcsRevision = result.vcsRevision @@ -532,15 +615,17 @@ proc downloadPkg*(url: string, verRange: VersionRange, if validateRange and verRange.kind notin {verSpecial, verAny} or not options.isLegacy: ## Makes sure that the downloaded package's version satisfies the requested ## version range. - pkginfo = if options.satResult.pass in {satNimSelection, satFallbackToVmParser}: #TODO later when in vnext we should just use this code path and fallback inside the toRequires if we can - getPkgInfoFromDirWithDeclarativeParser(result.dir, options) - else: - getPkgInfo(result.dir, options) + pkginfo = + if options.satResult.pass in {satNimSelection, satFallbackToVmParser}: + #TODO later when in vnext we should just use this code path and fallback inside the toRequires if we can + getPkgInfoFromDirWithDeclarativeParser(result.dir, options) + else: + getPkgInfo(result.dir, options) if pkginfo.basicInfo.version notin verRange: raise nimbleError( "Downloaded package's version does not satisfy requested version " & - "range: wanted $1 got $2." % - [$verRange, $pkginfo.basicInfo.version]) + "range: wanted $1 got $2." % [$verRange, $pkginfo.basicInfo.version] + ) #TODO rework the pkgcache to handle this better #ideally we should be able to know the version we are downloading upfront @@ -567,14 +652,18 @@ proc echoPackageVersions*(pkg: Package) = let sortedVersions = toSeq(values(versions)) displayInfoLine(" versions: ", join(sortedVersions, ", ")) else: - displayInfoLine(" versions: ", "(No versions tagged in the remote repository)") + displayInfoLine( + " versions: ", "(No versions tagged in the remote repository)" + ) except CatchableError: displayFormatted(Error, " Error: ") displayFormatted(Error, getCurrentExceptionMsg()) displayFormatted(Hint, "\n") of DownloadMethod.hg: - displayInfoLine(" versions: ", "(Remote tag retrieval not supported by " & - $pkg.downloadMethod & ")") + displayInfoLine( + " versions: ", + "(Remote tag retrieval not supported by " & $pkg.downloadMethod & ")", + ) proc removeTrailingSlash(s: string): string = s.strip(chars = {'/'}, leading = false) @@ -606,10 +695,7 @@ proc refresh*(options: Options) = raise nimbleError("Cannot refresh package list in offline mode.") let parameter = - if options.action.typ == actionRefresh: - options.action.optionalURL - else: - "" + if options.action.typ == actionRefresh: options.action.optionalURL else: "" if parameter.len > 0: if parameter.isUrl: @@ -627,11 +713,8 @@ proc refresh*(options: Options) = fetchList(list, options) proc getDownloadInfo*( - pv: PkgTuple, options: Options, - doPrompt: bool, - ignorePackageCache = false, + pv: PkgTuple, options: Options, doPrompt: bool, ignorePackageCache = false ): (DownloadMethod, string, Table[string, string]) = - # echo "getDownloadInfo:pv.name: ", $pv.name var pkg = initPackage() if getPackage(pv.name, options, pkg, ignorePackageCache): @@ -652,8 +735,10 @@ proc getDownloadInfo*( # If package is not found give the user a chance to refresh # package.json if doPrompt and not options.offline and - options.prompt(pv.name & " not found in any local packages.json, " & - "check internet for updated packages?"): + options.prompt( + pv.name & " not found in any local packages.json, " & + "check internet for updated packages?" + ): refresh(options) # Once we've refreshed, try again, but don't prompt if not found @@ -669,62 +754,70 @@ when isMainModule: suite "version sorting": test "pre-release versions": - let data = @["v9.0.0-taeyeon", "v9.0.1-jessica", "v9.2.0-sunny", - "v9.4.0-tiffany", "v9.4.2-hyoyeon"] - let expected = toOrderedTable[Version, string]({ - newVersion("9.4.2-hyoyeon"): "v9.4.2-hyoyeon", - newVersion("9.4.0-tiffany"): "v9.4.0-tiffany", - newVersion("9.2.0-sunny"): "v9.2.0-sunny", - newVersion("9.0.1-jessica"): "v9.0.1-jessica", - newVersion("9.0.0-taeyeon"): "v9.0.0-taeyeon"}) + let data = + @[ + "v9.0.0-taeyeon", "v9.0.1-jessica", "v9.2.0-sunny", "v9.4.0-tiffany", + "v9.4.2-hyoyeon", + ] + let expected = toOrderedTable[Version, string]( + { + newVersion("9.4.2-hyoyeon"): "v9.4.2-hyoyeon", + newVersion("9.4.0-tiffany"): "v9.4.0-tiffany", + newVersion("9.2.0-sunny"): "v9.2.0-sunny", + newVersion("9.0.1-jessica"): "v9.0.1-jessica", + newVersion("9.0.0-taeyeon"): "v9.0.0-taeyeon", + } + ) check getVersionList(data) == expected test "release versions": - let data = @["v0.1.0", "v0.1.1", "v0.2.0", - "0.4.0", "v0.4.2"] - let expected = toOrderedTable[Version, string]({ - newVersion("0.4.2"): "v0.4.2", - newVersion("0.4.0"): "0.4.0", - newVersion("0.2.0"): "v0.2.0", - newVersion("0.1.1"): "v0.1.1", - newVersion("0.1.0"): "v0.1.0",}) + let data = @["v0.1.0", "v0.1.1", "v0.2.0", "0.4.0", "v0.4.2"] + let expected = toOrderedTable[Version, string]( + { + newVersion("0.4.2"): "v0.4.2", + newVersion("0.4.0"): "0.4.0", + newVersion("0.2.0"): "v0.2.0", + newVersion("0.1.1"): "v0.1.1", + newVersion("0.1.0"): "v0.1.0", + } + ) check getVersionList(data) == expected suite "getDevelopDownloadDir": let dummyOptionsWithoutPath = Options(action: Action(typ: actionDevelop)) - let dummyOptionsWithAbsolutePath = Options( - action: Action(typ: actionDevelop, path: "/some/dir/")) - let dummyOptionsWithRelativePath = Options( - action: Action(typ: actionDevelop, path: "some/dir/")) + let dummyOptionsWithAbsolutePath = + Options(action: Action(typ: actionDevelop, path: "/some/dir/")) + let dummyOptionsWithRelativePath = + Options(action: Action(typ: actionDevelop, path: "some/dir/")) test "without subdir and without path": check getDevelopDownloadDir( - "https://github.com/nimble-test/packagea/", "", - dummyOptionsWithoutPath) == getCurrentDir() / "packagea" + "https://github.com/nimble-test/packagea/", "", dummyOptionsWithoutPath + ) == getCurrentDir() / "packagea" test "without subdir and with absolute path": check getDevelopDownloadDir( - "https://github.com/nimble-test/packagea", "", - dummyOptionsWithAbsolutePath) == "/some/dir/packagea".normalizedPath + "https://github.com/nimble-test/packagea", "", dummyOptionsWithAbsolutePath + ) == "/some/dir/packagea".normalizedPath test "without subdir and with relative path": check getDevelopDownloadDir( - "https://github.com/nimble-test/packagea/", "", - dummyOptionsWithRelativePath) == getCurrentDir() / "some/dir/packagea" + "https://github.com/nimble-test/packagea/", "", dummyOptionsWithRelativePath + ) == getCurrentDir() / "some/dir/packagea" test "with subdir and without path": check getDevelopDownloadDir( - "https://github.com/nimble-test/multi", "beta", - dummyOptionsWithoutPath) == getCurrentDir() / "beta" + "https://github.com/nimble-test/multi", "beta", dummyOptionsWithoutPath + ) == getCurrentDir() / "beta" test "with subdir and with absolute path": check getDevelopDownloadDir( - "https://github.com/nimble-test/multi/", "alpha/", - dummyOptionsWithAbsolutePath) == "/some/dir/alpha".normalizedPath + "https://github.com/nimble-test/multi/", "alpha/", dummyOptionsWithAbsolutePath + ) == "/some/dir/alpha".normalizedPath test "with subdir and with relative path": check getDevelopDownloadDir( - "https://github.com/nimble-test/multi", "alpha/", - dummyOptionsWithRelativePath) == getCurrentDir() / "some/dir/alpha" + "https://github.com/nimble-test/multi", "alpha/", dummyOptionsWithRelativePath + ) == getCurrentDir() / "some/dir/alpha" export urls