summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lib/pure/streams.nim2
-rw-r--r--tests/osproc/tstdin.nim11
2 files changed, 7 insertions, 6 deletions
diff --git a/lib/pure/streams.nim b/lib/pure/streams.nim
index 025a534c5..8fb14b6f6 100644
--- a/lib/pure/streams.nim
+++ b/lib/pure/streams.nim
@@ -321,6 +321,8 @@ proc readLine*(s: Stream): TaintedString =
   ## Reads a line from a stream `s`. Note: This is not very efficient. Raises
   ## `EIO` if an error occurred.
   result = TaintedString""
+  if s.atEnd:
+    raise newEIO("cannot read from stream")
   while true:
     var c = readChar(s)
     if c == '\c':
diff --git a/tests/osproc/tstdin.nim b/tests/osproc/tstdin.nim
index d94c34192..9b49ed786 100644
--- a/tests/osproc/tstdin.nim
+++ b/tests/osproc/tstdin.nim
@@ -11,9 +11,8 @@ doAssert fileExists(getCurrentDir() / "tests" / "osproc" / filename)
 var p = startProcess(filename, getCurrentDir() / "tests" / "osproc")
 p.inputStream.write("5\n")
 p.inputStream.flush()
-while true:
-  let line = p.outputStream.readLine()
-  if line != "":
-    echo line
-  else:
-    break
+
+var line = ""
+
+while p.outputStream.readLine(line.TaintedString):
+  echo line