Refactored version of execProcesses with test.
This commit is contained in:
parent
2a7cfe4043
commit
c6c0d28a4f
2 changed files with 115 additions and 54 deletions
32
tests/osproc/texecps.nim
Normal file
32
tests/osproc/texecps.nim
Normal file
|
|
@ -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))
|
||||
Loading…
Add table
Add a link
Reference in a new issue