@@ -7,9 +7,10 @@ discard """
7
7
8
8
import std/ [strformat,os,osproc ,strutils]
9
9
10
+ const nim = getCurrentCompilerExe()
11
+
10
12
proc runCmd(file, options = " " ): auto =
11
13
let mode = if existsEnv(" NIM_COMPILE_TO_CPP" ): " cpp" else : " c"
12
- const nim = getCurrentCompilerExe()
13
14
const testsDir = currentSourcePath().parentDir
14
15
let fileabs = testsDir / file.unixToNativePath
15
16
doAssert fileabs.existsFile, fileabs
@@ -60,3 +61,32 @@ else: # don't run twice the same test
60
61
check " sizeof(Foo5) == 3"
61
62
check " sizeof(struct Foo6) == "
62
63
doAssert exitCode != 0
64
+
65
+ import streams
66
+ block : # stdin input
67
+ let nimcmd = fmt" { nim} r --hints:off - -firstparam '-second param'"
68
+ let inputcmd = " import os; echo commandLineParams()"
69
+ let expected = """ @["-firstparam", "-second param"] """
70
+ block :
71
+ let p = startProcess(nimcmd, options = {poEvalCommand})
72
+ p.inputStream.write(" import os; echo commandLineParams()" )
73
+ p.inputStream.close
74
+ var output = p.outputStream.readAll
75
+ let error = p.errorStream.readAll
76
+ doAssert p.waitForExit == 0
77
+ when false : # https://github.com/timotheecour/Nim/issues/152
78
+ # bug: `^[[0m` is being inserted somehow with `-` (regarless of --run)
79
+ doAssert error.len == 0 , $ (error,)
80
+ output.stripLineEnd
81
+ doAssert output == expected
82
+ p.errorStream.close
83
+ p.outputStream.close
84
+
85
+ block :
86
+ when defined(posix):
87
+ let cmd = fmt" echo 'import os; echo commandLineParams()' | { nimcmd} "
88
+ # avoid https://github.com/timotheecour/Nim/issues/152 by
89
+ # making sure `poStdErrToStdOut` isn't passed
90
+ var (output, exitCode) = execCmdEx(cmd, options = {poEvalCommand})
91
+ output.stripLineEnd
92
+ doAssert output == expected
0 commit comments