From 68a9c4c955c6abc501a7b5d2f197081a79347d57 Mon Sep 17 00:00:00 2001 From: Daniel M Date: Wed, 19 Feb 2020 15:20:59 -0800 Subject: [PATCH] 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 --- src/nimble.nim | 9 ++++----- tests/tester.nim | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/nimble.nim b/src/nimble.nim index 6d233f6..e923eec 100644 --- a/src/nimble.nim +++ b/src/nimble.nim @@ -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: diff --git a/tests/tester.nim b/tests/tester.nim index c5d9925..446fecb 100644 --- a/tests/tester.nim +++ b/tests/tester.nim @@ -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")