Fix tests. Add test for hooks.
This commit is contained in:
parent
42ef358459
commit
1fa209a689
6 changed files with 49 additions and 8 deletions
|
|
@ -859,10 +859,15 @@ proc listTasks(options: Options) =
|
|||
proc execHook(options: Options, before: bool): bool =
|
||||
## Returns whether to continue.
|
||||
result = true
|
||||
let nimbleFile = findNimbleFile(getCurrentDir(), true)
|
||||
var nimbleFile = ""
|
||||
try:
|
||||
nimbleFile = findNimbleFile(getCurrentDir(), true)
|
||||
except NimbleError: return true
|
||||
# PackageInfos are cached so we can read them as many times as we want.
|
||||
let pkgInfo = readPackageInfo(nimbleFile, options)
|
||||
let actionName = ($options.action.typ)[6 .. ^1]
|
||||
let actionName =
|
||||
if options.action.typ == actionCustom: options.action.command
|
||||
else: ($options.action.typ)[6 .. ^1]
|
||||
let hookExists =
|
||||
if before: actionName.normalize in pkgInfo.preHooks
|
||||
else: actionName.normalize in pkgInfo.postHooks
|
||||
|
|
@ -877,7 +882,9 @@ proc doAction(options: Options) =
|
|||
if not existsDir(options.getPkgsDir):
|
||||
createDir(options.getPkgsDir)
|
||||
|
||||
if not execHook(options, true): return
|
||||
if not execHook(options, true):
|
||||
echo("Pre-hook prevented further execution.")
|
||||
return
|
||||
case options.action.typ
|
||||
of actionUpdate:
|
||||
update(options)
|
||||
|
|
|
|||
|
|
@ -39,4 +39,6 @@ template after*(action: untyped, body: untyped): untyped =
|
|||
template builtin = discard
|
||||
|
||||
proc getPkgDir*(): string =
|
||||
## Returns the package directory containing the .nimble file currently
|
||||
## being evaluated.
|
||||
builtin
|
||||
|
|
@ -229,7 +229,7 @@ proc execScript(scriptName: string, flags: StringTableRef, options: Options) =
|
|||
body
|
||||
|
||||
cbApi getPkgDir:
|
||||
setResult(a, "FOOBAR")
|
||||
setResult(a, scriptName.splitFile.dir)
|
||||
|
||||
compileSystemModule()
|
||||
processModule(m, llStreamOpen(scriptName, fmRead), nil)
|
||||
|
|
|
|||
|
|
@ -230,7 +230,8 @@ proc readPackageInfo*(nf: NimbleFile, options: Options,
|
|||
raise newException(NimbleError, msg)
|
||||
|
||||
validatePackageInfo(result, nf)
|
||||
options.pkgInfoCache[nf] = result
|
||||
if not result.isMinimal:
|
||||
options.pkgInfoCache[nf] = result
|
||||
|
||||
proc getPkgInfo*(dir: string, options: Options): PackageInfo =
|
||||
## Find the .nimble file in ``dir`` and parses it, returning a PackageInfo.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue