diff options
author | cheatfate <ka@hardcore.kiev.ua> | 2017-11-28 14:03:09 +0200 |
---|---|---|
committer | cheatfate <ka@hardcore.kiev.ua> | 2017-11-28 14:03:09 +0200 |
commit | c6c0d28a4f1811c20782d3322f5caf2c8d4b2128 (patch) | |
tree | 8283f754acd94e02635f36391f63c81f5048ce9b /tests/osproc | |
parent | 2a7cfe4043906aafdb22df44dc804734706f52ad (diff) | |
download | Nim-c6c0d28a4f1811c20782d3322f5caf2c8d4b2128.tar.gz |
Refactored version of execProcesses with test.
Diffstat (limited to 'tests/osproc')
-rw-r--r-- | tests/osproc/texecps.nim | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/osproc/texecps.nim b/tests/osproc/texecps.nim new file mode 100644 index 000000000..887d79bfb --- /dev/null +++ b/tests/osproc/texecps.nim @@ -0,0 +1,32 @@ +discard """ + file: "texecps.nim" + output: "" +""" + +import osproc, streams, strutils, os + +const NumberOfProcesses = 13 + +var gResults {.threadvar.}: seq[string] + +proc execCb(idx: int, p: Process) = + let exitCode = p.peekExitCode + if exitCode < len(gResults): + gResults[exitCode] = p.outputStream.readAll.strip + +when isMainModule: + + if paramCount() == 0: + gResults = newSeq[string](NumberOfProcesses) + var checks = newSeq[string](NumberOfProcesses) + var commands = newSeq[string](NumberOfProcesses) + for i in 0..len(commands) - 1: + commands[i] = getAppFileName() & " " & $i + checks[i] = $i + let cres = execProcesses(commands, options = {poStdErrToStdOut}, + afterRunEvent = execCb) + doAssert(cres == len(commands) - 1) + doAssert(gResults == checks) + else: + echo paramStr(1) + programResult = parseInt(paramStr(1)) |