Bugfix/double newlines in stderr (#5426)

This commit is contained in:
Fabian Keller
2017-02-24 09:48:38 +01:00
committed by Andreas Rumpf
parent 2d546ca0ac
commit e8ad59fdc4
6 changed files with 52 additions and 4 deletions

View File

@@ -2743,6 +2743,7 @@ when not defined(JS): #and not defined(nimscript):
# we use binary mode on Windows:
c_setmode(c_fileno(stdin), O_BINARY)
c_setmode(c_fileno(stdout), O_BINARY)
c_setmode(c_fileno(stderr), O_BINARY)
when defined(endb):
proc endbStep()

View File

@@ -1,3 +0,0 @@
import strutils
let x = stdin.readLine()
echo x.parseInt + 5

5
tests/osproc/ta_in.nim Normal file
View File

@@ -0,0 +1,5 @@
# This file is prefixed with an "a", because other tests
# depend on it and it must be compiled first.
import strutils
let x = stdin.readLine()
echo x.parseInt + 5

16
tests/osproc/ta_out.nim Normal file
View File

@@ -0,0 +1,16 @@
# This file is prefixed with an "a", because other tests
# depend on it and it must be compiled first.
stdout.writeLine("to stdout")
stdout.flushFile()
stdout.writeLine("to stdout")
stdout.flushFile()
stderr.writeLine("to stderr")
stderr.flushFile()
stderr.writeLine("to stderr")
stderr.flushFile()
stdout.writeLine("to stdout")
stdout.flushFile()
stdout.writeLine("to stdout")
stdout.flushFile()

View File

@@ -4,7 +4,7 @@ discard """
"""
import osproc, os, streams
const filename = when defined(Windows): "ta.exe" else: "ta"
const filename = when defined(Windows): "ta_in.exe" else: "ta_in"
doAssert fileExists(getCurrentDir() / "tests" / "osproc" / filename)

29
tests/osproc/tstdout.nim Normal file
View File

@@ -0,0 +1,29 @@
discard """
output: '''--------------------------------------
to stdout
to stdout
to stderr
to stderr
to stdout
to stdout
--------------------------------------
'''
"""
import osproc, os, streams
const filename = when defined(Windows): "ta_out.exe" else: "ta_out"
doAssert fileExists(getCurrentDir() / "tests" / "osproc" / filename)
var p = startProcess(filename, getCurrentDir() / "tests" / "osproc",
options={poStdErrToStdOut})
let outputStream = p.outputStream
var x = newStringOfCap(120)
var output = ""
while outputStream.readLine(x.TaintedString):
output.add(x & "\n")
echo "--------------------------------------"
stdout.write output
echo "--------------------------------------"