workaround for nim 1.2 backward compatibility: exception in terminal.nim

This commit is contained in:
jangko 2023-02-14 10:44:13 +07:00
parent bed1d50a45
commit 828310e512
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9

View File

@ -366,6 +366,11 @@ method suiteStarted*(formatter: ConsoleOutputFormatter, suiteName: string) =
template rawPrint() = echo("\n[Suite] ", suiteName) template rawPrint() = echo("\n[Suite] ", suiteName)
when useTerminal: when useTerminal:
if formatter.colorOutput: if formatter.colorOutput:
when (NimMajor, NimMinor) < (1, 4) and defined(windows):
try:
styledEcho styleBright, fgBlue, "\n[Suite] ", resetStyle, suiteName
except Exception: rawPrint() # Work around exceptions in `terminal.nim`
else:
try: try:
styledEcho styleBright, fgBlue, "\n[Suite] ", resetStyle, suiteName styledEcho styleBright, fgBlue, "\n[Suite] ", resetStyle, suiteName
except CatchableError: rawPrint() # Work around exceptions in `terminal.nim` except CatchableError: rawPrint() # Work around exceptions in `terminal.nim`
@ -411,6 +416,12 @@ method testEnded*(formatter: ConsoleOutputFormatter, testResult: TestResult) =
of TestStatus.OK: fgGreen of TestStatus.OK: fgGreen
of TestStatus.FAILED: fgRed of TestStatus.FAILED: fgRed
of TestStatus.SKIPPED: fgYellow of TestStatus.SKIPPED: fgYellow
when (NimMajor, NimMinor) < (1, 4) and defined(windows):
try:
styledEcho styleBright, color, testHeader,
resetStyle, testResult.testName
except Exception: rawPrint() # Work around exceptions in `terminal.nim`
else:
try: try:
styledEcho styleBright, color, testHeader, styledEcho styleBright, color, testHeader,
resetStyle, testResult.testName resetStyle, testResult.testName