Namespace unittest enums to avoid name conflicts (#12468) [backport]
* [backport] Fixes: #12465 - Unittest - Namespace the usage of TestStatus enum to avoid name conflicts.
This commit is contained in:
parent
0eae2217b6
commit
df4c339cfc
1 changed files with 14 additions and 14 deletions
|
|
@ -186,7 +186,7 @@ proc delOutputFormatter*(formatter: OutputFormatter) =
|
||||||
keepIf(formatters, proc (x: OutputFormatter): bool =
|
keepIf(formatters, proc (x: OutputFormatter): bool =
|
||||||
x != formatter)
|
x != formatter)
|
||||||
|
|
||||||
proc newConsoleOutputFormatter*(outputLevel: OutputLevel = PRINT_ALL,
|
proc newConsoleOutputFormatter*(outputLevel: OutputLevel = OutputLevel.PRINT_ALL,
|
||||||
colorOutput = true): <//>ConsoleOutputFormatter =
|
colorOutput = true): <//>ConsoleOutputFormatter =
|
||||||
ConsoleOutputFormatter(
|
ConsoleOutputFormatter(
|
||||||
outputLevel: outputLevel,
|
outputLevel: outputLevel,
|
||||||
|
|
@ -207,7 +207,7 @@ proc defaultConsoleFormatter*(): <//>ConsoleOutputFormatter =
|
||||||
colorOutput = true
|
colorOutput = true
|
||||||
elif existsEnv("NIMTEST_NO_COLOR"):
|
elif existsEnv("NIMTEST_NO_COLOR"):
|
||||||
colorOutput = false
|
colorOutput = false
|
||||||
var outputLevel = PRINT_ALL
|
var outputLevel = OutputLevel.PRINT_ALL
|
||||||
if envOutLvl.len > 0:
|
if envOutLvl.len > 0:
|
||||||
for opt in countup(low(OutputLevel), high(OutputLevel)):
|
for opt in countup(low(OutputLevel), high(OutputLevel)):
|
||||||
if $opt == envOutLvl:
|
if $opt == envOutLvl:
|
||||||
|
|
@ -240,17 +240,17 @@ method failureOccurred*(formatter: ConsoleOutputFormatter,
|
||||||
method testEnded*(formatter: ConsoleOutputFormatter, testResult: TestResult) =
|
method testEnded*(formatter: ConsoleOutputFormatter, testResult: TestResult) =
|
||||||
formatter.isInTest = false
|
formatter.isInTest = false
|
||||||
|
|
||||||
if formatter.outputLevel != PRINT_NONE and
|
if formatter.outputLevel != OutputLevel.PRINT_NONE and
|
||||||
(formatter.outputLevel == PRINT_ALL or testResult.status == FAILED):
|
(formatter.outputLevel == OutputLevel.PRINT_ALL or testResult.status == TestStatus.FAILED):
|
||||||
let prefix = if testResult.suiteName.len > 0: " " else: ""
|
let prefix = if testResult.suiteName.len > 0: " " else: ""
|
||||||
template rawPrint() = echo(prefix, "[", $testResult.status, "] ",
|
template rawPrint() = echo(prefix, "[", $testResult.status, "] ",
|
||||||
testResult.testName)
|
testResult.testName)
|
||||||
when not defined(ECMAScript):
|
when not defined(ECMAScript):
|
||||||
if formatter.colorOutput and not defined(ECMAScript):
|
if formatter.colorOutput and not defined(ECMAScript):
|
||||||
var color = case testResult.status
|
var color = case testResult.status
|
||||||
of OK: fgGreen
|
of TestStatus.OK: fgGreen
|
||||||
of FAILED: fgRed
|
of TestStatus.FAILED: fgRed
|
||||||
of SKIPPED: fgYellow
|
of TestStatus.SKIPPED: fgYellow
|
||||||
styledEcho styleBright, color, prefix, "[", $testResult.status, "] ",
|
styledEcho styleBright, color, prefix, "[", $testResult.status, "] ",
|
||||||
resetStyle, testResult.testName
|
resetStyle, testResult.testName
|
||||||
else:
|
else:
|
||||||
|
|
@ -318,11 +318,11 @@ method testEnded*(formatter: JUnitOutputFormatter, testResult: TestResult) =
|
||||||
formatter.stream.writeLine("\t\t<testcase name=\"$#\" time=\"$#\">" % [
|
formatter.stream.writeLine("\t\t<testcase name=\"$#\" time=\"$#\">" % [
|
||||||
xmlEscape(testResult.testName), timeStr])
|
xmlEscape(testResult.testName), timeStr])
|
||||||
case testResult.status
|
case testResult.status
|
||||||
of OK:
|
of TestStatus.OK:
|
||||||
discard
|
discard
|
||||||
of SKIPPED:
|
of TestStatus.SKIPPED:
|
||||||
formatter.stream.writeLine("<skipped />")
|
formatter.stream.writeLine("<skipped />")
|
||||||
of FAILED:
|
of TestStatus.FAILED:
|
||||||
let failureMsg = if formatter.testStackTrace.len > 0 and
|
let failureMsg = if formatter.testStackTrace.len > 0 and
|
||||||
formatter.testErrors.len > 0:
|
formatter.testErrors.len > 0:
|
||||||
xmlEscape(formatter.testErrors[^1])
|
xmlEscape(formatter.testErrors[^1])
|
||||||
|
|
@ -498,7 +498,7 @@ template test*(name, body) {.dirty.} =
|
||||||
|
|
||||||
if shouldRun(when declared(testSuiteName): testSuiteName else: "", name):
|
if shouldRun(when declared(testSuiteName): testSuiteName else: "", name):
|
||||||
checkpoints = @[]
|
checkpoints = @[]
|
||||||
var testStatusIMPL {.inject.} = OK
|
var testStatusIMPL {.inject.} = TestStatus.OK
|
||||||
|
|
||||||
for formatter in formatters:
|
for formatter in formatters:
|
||||||
formatter.testStarted(name)
|
formatter.testStarted(name)
|
||||||
|
|
@ -518,7 +518,7 @@ template test*(name, body) {.dirty.} =
|
||||||
fail()
|
fail()
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
if testStatusIMPL == FAILED:
|
if testStatusIMPL == TestStatus.FAILED:
|
||||||
programResult = 1
|
programResult = 1
|
||||||
let testResult = TestResult(
|
let testResult = TestResult(
|
||||||
suiteName: when declared(testSuiteName): testSuiteName else: "",
|
suiteName: when declared(testSuiteName): testSuiteName else: "",
|
||||||
|
|
@ -558,7 +558,7 @@ template fail* =
|
||||||
bind ensureInitialized
|
bind ensureInitialized
|
||||||
|
|
||||||
when declared(testStatusIMPL):
|
when declared(testStatusIMPL):
|
||||||
testStatusIMPL = FAILED
|
testStatusIMPL = TestStatus.FAILED
|
||||||
else:
|
else:
|
||||||
programResult = 1
|
programResult = 1
|
||||||
|
|
||||||
|
|
@ -589,7 +589,7 @@ template skip* =
|
||||||
## skip()
|
## skip()
|
||||||
bind checkpoints
|
bind checkpoints
|
||||||
|
|
||||||
testStatusIMPL = SKIPPED
|
testStatusIMPL = TestStatus.SKIPPED
|
||||||
checkpoints = @[]
|
checkpoints = @[]
|
||||||
|
|
||||||
macro check*(conditions: untyped): untyped =
|
macro check*(conditions: untyped): untyped =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue