diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2020-05-11 02:14:21 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-11 11:14:21 +0200 |
commit | d11cb9d49596957e9fa097110cf19e9caf085592 (patch) | |
tree | b8abdf221a548566eed5f7b003dc8f7ca8097d94 /tests/stdlib | |
parent | 8018449319746f04a0c6436f1a0a3a5c6798d95c (diff) | |
download | Nim-d11cb9d49596957e9fa097110cf19e9caf085592.tar.gz |
fix a critical bug in windows.osproc leading to resource leaks and blocking IO [backport] (#14296)
Diffstat (limited to 'tests/stdlib')
-rw-r--r-- | tests/stdlib/tosproc.nim | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/stdlib/tosproc.nim b/tests/stdlib/tosproc.nim index fc65606f6..73cec0cb7 100644 --- a/tests/stdlib/tosproc.nim +++ b/tests/stdlib/tosproc.nim @@ -93,3 +93,29 @@ else: removeFile(exePath) except OSError: discard + + import std/streams + block: # test for startProcess (more tests needed) + # bugfix: windows stdin.close was a noop and led to blocking reads + proc startProcessTest(command: string, options: set[ProcessOption] = { + poStdErrToStdOut, poUsePath}, input = ""): tuple[ + output: TaintedString, + exitCode: int] {.tags: + [ExecIOEffect, ReadIOEffect, RootEffect], gcsafe.} = + var p = startProcess(command, options = options + {poEvalCommand}) + var outp = outputStream(p) + if input.len > 0: inputStream(p).write(input) + close inputStream(p) + result = (TaintedString"", -1) + var line = newStringOfCap(120).TaintedString + while true: + if outp.readLine(line): + result[0].string.add(line.string) + result[0].string.add("\n") + else: + result[1] = peekExitCode(p) + if result[1] != -1: break + close(p) + + var result = startProcessTest("nim r --hints:off -", options = {}, input = "echo 3*4") + doAssert result == ("12\n", 0) |