diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2020-05-04 02:27:59 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-04 11:27:59 +0200 |
commit | f115e40e6a5721b34d41d4ad58e47e194f0e7788 (patch) | |
tree | 83b103fc58c0c5c1d4a32c9ece1e85279378cc98 | |
parent | a73d40390167282de40c0cb8d0075cd944827708 (diff) | |
download | Nim-f115e40e6a5721b34d41d4ad58e47e194f0e7788.tar.gz |
`echo cmd | nim r - -arg1 -arg2` now works (#14210)
-rw-r--r-- | compiler/nim.nim | 2 | ||||
-rw-r--r-- | tests/trunner.nim | 32 |
2 files changed, 32 insertions, 2 deletions
diff --git a/compiler/nim.nim b/compiler/nim.nim index 7fe0db5cf..80d9b66b6 100644 --- a/compiler/nim.nim +++ b/compiler/nim.nim @@ -52,7 +52,7 @@ proc processCmdLine(pass: TCmdLinePass, cmd: string; config: ConfigRef) = config.commandLine.add ':' config.commandLine.add p.val.quoteShell - if p.key == " ": + if p.key == "": # `-` was passed to indicate main project is stdin p.key = "-" if processArgument(pass, p, argsCount, config): break else: diff --git a/tests/trunner.nim b/tests/trunner.nim index 263184571..65016d2f1 100644 --- a/tests/trunner.nim +++ b/tests/trunner.nim @@ -7,9 +7,10 @@ discard """ import std/[strformat,os,osproc,strutils] +const nim = getCurrentCompilerExe() + proc runCmd(file, options = ""): auto = let mode = if existsEnv("NIM_COMPILE_TO_CPP"): "cpp" else: "c" - const nim = getCurrentCompilerExe() const testsDir = currentSourcePath().parentDir let fileabs = testsDir / file.unixToNativePath doAssert fileabs.existsFile, fileabs @@ -60,3 +61,32 @@ else: # don't run twice the same test check "sizeof(Foo5) == 3" check "sizeof(struct Foo6) == " doAssert exitCode != 0 + + import streams + block: # stdin input + let nimcmd = fmt"{nim} r --hints:off - -firstparam '-second param'" + let inputcmd = "import os; echo commandLineParams()" + let expected = """@["-firstparam", "-second param"]""" + block: + let p = startProcess(nimcmd, options = {poEvalCommand}) + p.inputStream.write("import os; echo commandLineParams()") + p.inputStream.close + var output = p.outputStream.readAll + let error = p.errorStream.readAll + doAssert p.waitForExit == 0 + when false: # https://github.com/timotheecour/Nim/issues/152 + # bug: `^[[0m` is being inserted somehow with `-` (regarless of --run) + doAssert error.len == 0, $(error,) + output.stripLineEnd + doAssert output == expected + p.errorStream.close + p.outputStream.close + + block: + when defined(posix): + let cmd = fmt"echo 'import os; echo commandLineParams()' | {nimcmd}" + # avoid https://github.com/timotheecour/Nim/issues/152 by + # making sure `poStdErrToStdOut` isn't passed + var (output, exitCode) = execCmdEx(cmd, options = {poEvalCommand}) + output.stripLineEnd + doAssert output == expected |