fix https://github.com/timotheecour/Nim/issues/152: avoid writing spurious ^[[0m to stderr when callStyledWriteLineStderr not called (#14214)
* fix https://github.com/timotheecour/Nim/issues/152 `^[[0m` is inserted in stderr for `echo code | nim c -` * resetAttributes not even needed, already handled in styledWriteLine * simplify tests in tests/trunner.nim thanks to this fix
This commit is contained in:
parent
927737975c
commit
a23302ef56
3 changed files with 5 additions and 12 deletions
|
|
@ -405,5 +405,3 @@ proc mainCommand*(graph: ModuleGraph) =
|
||||||
echo " int tries: ", gCacheIntTries
|
echo " int tries: ", gCacheIntTries
|
||||||
echo " efficiency: ", formatFloat(1-(gCacheMisses.float/gCacheTries.float),
|
echo " efficiency: ", formatFloat(1-(gCacheMisses.float/gCacheTries.float),
|
||||||
ffDecimal, 3)
|
ffDecimal, 3)
|
||||||
|
|
||||||
resetAttributes(conf)
|
|
||||||
|
|
|
||||||
|
|
@ -298,6 +298,9 @@ macro callStyledWriteLineStderr(args: varargs[typed]): untyped =
|
||||||
result.add(bindSym"stderr")
|
result.add(bindSym"stderr")
|
||||||
for arg in children(args[0][1]):
|
for arg in children(args[0][1]):
|
||||||
result.add(arg)
|
result.add(arg)
|
||||||
|
when false:
|
||||||
|
# not needed because styledWriteLine already ends with resetAttributes
|
||||||
|
result = newStmtList(result, newCall(bindSym"resetAttributes", bindSym"stderr"))
|
||||||
|
|
||||||
template callWritelnHook(args: varargs[string, `$`]) =
|
template callWritelnHook(args: varargs[string, `$`]) =
|
||||||
conf.writelnHook concat(args)
|
conf.writelnHook concat(args)
|
||||||
|
|
@ -441,10 +444,6 @@ proc rawMessage*(conf: ConfigRef; msg: TMsgKind, args: openArray[string]) =
|
||||||
proc rawMessage*(conf: ConfigRef; msg: TMsgKind, arg: string) =
|
proc rawMessage*(conf: ConfigRef; msg: TMsgKind, arg: string) =
|
||||||
rawMessage(conf, msg, [arg])
|
rawMessage(conf, msg, [arg])
|
||||||
|
|
||||||
proc resetAttributes*(conf: ConfigRef) =
|
|
||||||
if {optUseColors, optStdout} * conf.globalOptions == {optUseColors}:
|
|
||||||
terminal.resetAttributes(stderr)
|
|
||||||
|
|
||||||
proc addSourceLine(conf: ConfigRef; fileIdx: FileIndex, line: string) =
|
proc addSourceLine(conf: ConfigRef; fileIdx: FileIndex, line: string) =
|
||||||
conf.m.fileInfos[fileIdx.int32].lines.add line
|
conf.m.fileInfos[fileIdx.int32].lines.add line
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,9 +74,7 @@ else: # don't run twice the same test
|
||||||
var output = p.outputStream.readAll
|
var output = p.outputStream.readAll
|
||||||
let error = p.errorStream.readAll
|
let error = p.errorStream.readAll
|
||||||
doAssert p.waitForExit == 0
|
doAssert p.waitForExit == 0
|
||||||
when false: # https://github.com/timotheecour/Nim/issues/152
|
doAssert error.len == 0, $error
|
||||||
# bug: `^[[0m` is being inserted somehow with `-` (regarless of --run)
|
|
||||||
doAssert error.len == 0, $(error,)
|
|
||||||
output.stripLineEnd
|
output.stripLineEnd
|
||||||
doAssert output == expected
|
doAssert output == expected
|
||||||
p.errorStream.close
|
p.errorStream.close
|
||||||
|
|
@ -85,8 +83,6 @@ else: # don't run twice the same test
|
||||||
block:
|
block:
|
||||||
when defined(posix):
|
when defined(posix):
|
||||||
let cmd = fmt"echo 'import os; echo commandLineParams()' | {nimcmd}"
|
let cmd = fmt"echo 'import os; echo commandLineParams()' | {nimcmd}"
|
||||||
# avoid https://github.com/timotheecour/Nim/issues/152 by
|
var (output, exitCode) = execCmdEx(cmd)
|
||||||
# making sure `poStdErrToStdOut` isn't passed
|
|
||||||
var (output, exitCode) = execCmdEx(cmd, options = {poEvalCommand})
|
|
||||||
output.stripLineEnd
|
output.stripLineEnd
|
||||||
doAssert output == expected
|
doAssert output == expected
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue