fix and improve the behavior of nimble run

quote arguments appropriately:
  - whitespace in arguments is preserved;
    previously arguments with whitespace were split
  - quotes are now escaped

the exit code of the command that has been "run"
is re-used when nimble exits

show the output of the "run" command
regardless of whether nimble is debugging
This commit is contained in:
Daniel M 2020-02-19 15:20:59 -08:00 committed by Dominik Picheta
commit 68a9c4c955
2 changed files with 23 additions and 6 deletions

View file

@ -1124,15 +1124,14 @@ proc run(options: Options) =
"Binary '$#' is not defined in '$#' package." % [binary, pkgInfo.name]
)
let binaryPath = pkgInfo.getOutputDir(binary)
# Build the binary.
build(options)
# Now run it.
let args = options.action.runFlags.join(" ")
let binaryPath = pkgInfo.getOutputDir(binary)
let cmd = quoteShellCommand(binaryPath & options.action.runFlags)
displayDebug("Executing", cmd)
cmd.execCmd.quit
doCmd("$# $#" % [binaryPath, args], showOutput = true)
proc doAction(options: var Options) =
if options.showHelp:

View file

@ -38,7 +38,7 @@ proc execNimble(args: varargs[string]): tuple[output: string, exitCode: int] =
var quotedArgs = @args
quotedArgs.insert("--nimbleDir:" & installDir)
quotedArgs.insert(nimblePath)
quotedArgs = quotedArgs.map((x: string) => ("\"" & x & "\""))
quotedArgs = quotedArgs.map((x: string) => x.quoteShell)
let path {.used.} = getCurrentDir().parentDir() / "src"
@ -976,6 +976,24 @@ suite "nimble run":
[$DirSep, "run".changeFileExt(ExeExt)])
check output.contains("""Testing `nimble run`: @["--debug", "check"]""")
test "Executable output is shown even when not debugging":
cd "run":
var (output, exitCode) =
execNimble("run", "run", "--option1", "arg1")
check exitCode == QuitSuccess
check output.contains("""Testing `nimble run`: @["--option1", "arg1"]""")
test "Quotes and whitespace are well handled":
cd "run":
var (output, exitCode) = execNimble(
"run", "run", "\"", "\'", "\t", "arg with spaces"
)
check exitCode == QuitSuccess
check output.contains(
"""Testing `nimble run`: @["\"", "\'", "\t", "arg with spaces"]"""
)
test "NimbleVersion is defined":
cd "nimbleVersionDefine":
var (output, exitCode) = execNimble("c", "-r", "src/nimbleVersionDefine.nim")