Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
elcritch committed Jan 19, 2025
1 parent f18ce40 commit fd6b7b6
Showing 1 changed file with 12 additions and 78 deletions.
90 changes: 12 additions & 78 deletions tests/tpublish.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@

{.used.}

import unittest, os, strformat, json, strutils, sequtils
import unittest, os, strformat, json, strutils

import testscommon

import nimblepkg/displaymessages
import nimblepkg/sha1hashes
import nimblepkg/paths
import nimblepkg/vcstools

from nimblepkg/common import cd, dump, cdNewDir
from nimblepkg/tools import tryDoCmdEx, doCmdEx
from nimblepkg/packageinfotypes import DownloadMethod
from nimblepkg/lockfile import LockFileJsonKeys
from nimblepkg/options import defaultLockFileName
from nimblepkg/developfile import ValidationError, ValidationErrorKind,
developFileName, getValidationErrorMessage

suite "publish":
type
Expand All @@ -30,7 +25,7 @@ suite "publish":
description: string
license: string

PackagesListFileContent = seq[PackagesListFileRecord]
# PackagesListFileContent = seq[PackagesListFileRecord]

PkgIdent {.pure.} = enum
main = "main"
Expand Down Expand Up @@ -74,8 +69,8 @@ suite "publish":
additionalRemotesDirName = "remotes"
additionalRemotesDirPath = tempDir / additionalRemotesDirName

pkgListFileName = "packages.json"
pkgListFilePath = tempDir / pkgListFileName
# pkgListFileName = "packages.json"
# pkgListFilePath = tempDir / pkgListFileName

nimbleFileTemplate = """
Expand Down Expand Up @@ -104,16 +99,6 @@ requires "nim >= 1.5.1"
proc commit(msg: string) =
tryDoCmdEx("git commit -am " & msg.quoteShell)

proc push(remote: string) =
tryDoCmdEx(
&"git push --set-upstream {remote} {vcsTypeGit.getVcsDefaultBranchName}")

proc pull(remote: string) =
tryDoCmdEx("git pull " & remote)

proc addRemote(remoteName, remoteUrl: string) =
tryDoCmdEx(&"git remote add {remoteName} {remoteUrl}")

proc configUserAndEmail =
tryDoCmdEx("git config user.name \"John Doe\"")
tryDoCmdEx("git config user.email \"[email protected]\"")
Expand All @@ -123,27 +108,9 @@ requires "nim >= 1.5.1"
tryDoCmdEx("git init " & bare)
configUserAndEmail()

proc clone(urlFrom, pathTo: string) =
tryDoCmdEx(&"git clone {urlFrom} {pathTo}")
cd pathTo: configUserAndEmail()

proc branch(branchName: string) =
tryDoCmdEx(&"git branch {branchName}")

proc checkout(what: string) =
tryDoCmdEx(&"git checkout {what}")

proc getRepoRevision: string =
result = tryDoCmdEx("git rev-parse HEAD").replace("\n", "")

proc getRevision(dep: string, lockFileName = defaultLockFileName): string =
result = lockFileName.readFile.parseJson{$lfjkPackages}{dep}{$lfjkPkgVcsRevision}.str

proc createBranchAndSwitchToIt(branchName: string) =
if branchName.len > 0:
branch(branchName)
checkout(branchName)

proc initNewNimbleFile(dir: string, version: string): string =
let pkgName = dir.splitPath.tail
let nimbleFileName = pkgName & ".nimble"
Expand Down Expand Up @@ -173,47 +140,14 @@ requires "nim >= 1.5.1"
addAdditionalFileToTheRepo("test.txt", $idx)


proc testLockedVcsRevisions(deps: seq[tuple[name, path: string]], lockFileName = defaultLockFileName) =
check lockFileName.fileExists

let json = lockFileName.readFile.parseJson
for (depName, depPath) in deps:
let expectedVcsRevision = depPath.getVcsRevision
check depName in json{$lfjkPackages}
let lockedVcsRevision =
json{$lfjkPackages}{depName}{$lfjkPkgVcsRevision}.str.initSha1Hash
check lockedVcsRevision == expectedVcsRevision

template filesAndDirsToRemove() =
removeFile pkgListFilePath
removeDir installDir
removeDir tempDir

template cleanUp() =
filesAndDirsToRemove()
defer: filesAndDirsToRemove()

proc writePackageListFile(path: string, content: PackagesListFileContent) =
let dir = path.splitPath.head
createDir dir
writeFile(path, (%content).pretty)

template withPkgListFile(body: untyped) =
writePackageListFile(
pkgListFilePath, @[bad1PkgListFileRecord, dep2PkgListFileRecord])
usePackageListFile pkgListFilePath:
body

proc addAdditionalFileAndPushToRemote(
repoPath, remoteName, remotePath, fileContent: string) =
cdNewDir remotePath:
initRepo(isBare = true)
cd repoPath:
# Add commit to the dependency.
addAdditionalFileToTheRepo("dep1.nim", fileContent)
addRemote(remoteName, remotePath)
# Push it to the newly added remote to be able to lock.
push(remoteName)
# template filesAndDirsToRemove() =
# removeFile pkgListFilePath
# removeDir installDir
# removeDir tempDir

# template cleanUp() =
# filesAndDirsToRemove()
# defer: filesAndDirsToRemove()

test "test publishVersions basic find versions":
# cleanUp()
Expand Down

0 comments on commit fd6b7b6

Please sign in to comment.