From e8ad59fdc497843e712583cba03cfd1809124bfb Mon Sep 17 00:00:00 2001 From: Fabian Keller Date: Fri, 24 Feb 2017 09:48:38 +0100 Subject: [PATCH 1/4] Bugfix/double newlines in stderr (#5426) --- lib/system.nim | 1 + tests/osproc/ta.nim | 3 --- tests/osproc/ta_in.nim | 5 +++++ tests/osproc/ta_out.nim | 16 ++++++++++++++++ tests/osproc/tstdin.nim | 2 +- tests/osproc/tstdout.nim | 29 +++++++++++++++++++++++++++++ 6 files changed, 52 insertions(+), 4 deletions(-) delete mode 100644 tests/osproc/ta.nim create mode 100644 tests/osproc/ta_in.nim create mode 100644 tests/osproc/ta_out.nim create mode 100644 tests/osproc/tstdout.nim diff --git a/lib/system.nim b/lib/system.nim index bab5369f11..6388e278e1 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -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() diff --git a/tests/osproc/ta.nim b/tests/osproc/ta.nim deleted file mode 100644 index 5ebcc7f142..0000000000 --- a/tests/osproc/ta.nim +++ /dev/null @@ -1,3 +0,0 @@ -import strutils -let x = stdin.readLine() -echo x.parseInt + 5 diff --git a/tests/osproc/ta_in.nim b/tests/osproc/ta_in.nim new file mode 100644 index 0000000000..b46890f6ea --- /dev/null +++ b/tests/osproc/ta_in.nim @@ -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 diff --git a/tests/osproc/ta_out.nim b/tests/osproc/ta_out.nim new file mode 100644 index 0000000000..f7091a7f6a --- /dev/null +++ b/tests/osproc/ta_out.nim @@ -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() diff --git a/tests/osproc/tstdin.nim b/tests/osproc/tstdin.nim index b491c25000..d94c34192d 100644 --- a/tests/osproc/tstdin.nim +++ b/tests/osproc/tstdin.nim @@ -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) diff --git a/tests/osproc/tstdout.nim b/tests/osproc/tstdout.nim new file mode 100644 index 0000000000..0cb5bd9c08 --- /dev/null +++ b/tests/osproc/tstdout.nim @@ -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 "--------------------------------------" From 8ebc8697736acf2c7828fbe2dcb57c54ad48f760 Mon Sep 17 00:00:00 2001 From: Ivan Koster Date: Fri, 24 Feb 2017 15:43:31 +0100 Subject: [PATCH 2/4] Remove unnecessary colon in unittest.nim code example --- lib/pure/unittest.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pure/unittest.nim b/lib/pure/unittest.nim index cdca02ed79..01af0f8395 100644 --- a/lib/pure/unittest.nim +++ b/lib/pure/unittest.nim @@ -24,7 +24,7 @@ ## echo "run before each test" ## ## teardown: -## echo "run after each test": +## echo "run after each test" ## ## test "essential truths": ## # give up and stop if this fails From 469a7d258ce256ea22b3df3fe40fb7ec0ef129ef Mon Sep 17 00:00:00 2001 From: Federico Ceratto Date: Fri, 24 Feb 2017 14:58:02 +0000 Subject: [PATCH 3/4] Add warning about log flushing. Related to #3269 (#5424) --- lib/pure/logging.nim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/pure/logging.nim b/lib/pure/logging.nim index 5544a4b3f4..65724f75a6 100644 --- a/lib/pure/logging.nim +++ b/lib/pure/logging.nim @@ -46,6 +46,8 @@ ## ## **Warning:** The global list of handlers is a thread var, this means that ## the handlers must be re-added in each thread. +## **Warning:** When logging on disk or console, only error and fatal messages +## are flushed out immediately. Use flushFile() where needed. import strutils, times when not defined(js): From 4af2c26c918239fa79f7523e923b5bbceaafc272 Mon Sep 17 00:00:00 2001 From: Dennis Felsing Date: Fri, 24 Feb 2017 16:48:22 +0100 Subject: [PATCH 4/4] Make toHex work for uints (#5423) --- lib/pure/strutils.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index 9c205a54f2..9c9da92c61 100644 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -898,7 +898,7 @@ proc toHex*(x: BiggestInt, len: Positive): string {.noSideEffect, proc toHex*[T](x: T): string = ## Shortcut for ``toHex(x, T.sizeOf * 2)`` - toHex(x, T.sizeOf * 2) + toHex(BiggestInt(x), T.sizeOf * 2) proc intToStr*(x: int, minchars: Positive = 1): string {.noSideEffect, rtl, extern: "nsuIntToStr".} =