From 91d119fdb0ff55636efe636b04ae0fc6667b6484 Mon Sep 17 00:00:00 2001 From: jangko Date: Thu, 7 Jan 2021 12:12:55 +0700 Subject: [PATCH] fixes broken test --- .gitignore | 2 +- faststreams/inputs.nim | 4 ++-- tests/test_pipelines.nim | 10 +++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 5f3c68e..aea9e1e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ nimcache/ - +*.exe diff --git a/faststreams/inputs.nim b/faststreams/inputs.nim index 2ceaa7e..c9024ff 100644 --- a/faststreams/inputs.nim +++ b/faststreams/inputs.nim @@ -789,7 +789,7 @@ proc readInto*(s: InputStream, target: var openarray[byte]): bool = s.readIntoEx(target) == target.len template readIntoEx*(sp: AsyncInputStream, dst: var openarray[byte]): int = - let s = sp + let s = InputStream(sp) # BEWARE! `openArrayToPair` here is needed to avoid # double evaluation of the `dst` expression: let (dstAddr, dstLen) = openArrayToPair(dst) @@ -806,7 +806,7 @@ template readInto*(sp: AsyncInputStream, dst: var openarray[byte]): bool = ## the expression will complete immediately. ## Otherwise, it will await more bytes to become available. - let s = sp + let s = InputStream(sp) # BEWARE! `openArrayToPair` here is needed to avoid # double evaluation of the `dst` expression: let (dstAddr, dstLen) = openArrayToPair(dst) diff --git a/tests/test_pipelines.nim b/tests/test_pipelines.nim index 4405a23..f597540 100644 --- a/tests/test_pipelines.nim +++ b/tests/test_pipelines.nim @@ -38,6 +38,15 @@ template timeit(timerVar: var Nanos, code: untyped) = code timerVar = int(getTicks() - t0) div 1000000 +proc getOutput(sp: AsyncInputStream, T: type string): Future[string] {.async.} = + # this proc is a quick hack to let the test pass + # do not use it in production code + let size = sp.totalUnconsumedBytes() + if size > 0: + var data = newSeq[byte](size) + discard sp.readinto(data) + result = cast[string](data) + procSuite "pipelines": let loremIpsum = """ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod @@ -117,4 +126,3 @@ procSuite "pipelines": let fsAsyncres = await f check fsAsyncRes == toUpperAscii(inputText) -