commit
06afd454f4
4 changed files with 45 additions and 17 deletions
|
|
@ -39,6 +39,10 @@ nim c -r -d:noColors testing_script.nim
|
||||||
|
|
||||||
# No colors, quiet output
|
# No colors, quiet output
|
||||||
nim c -r -d:quiet -d:noColors testing_script.nim
|
nim c -r -d:quiet -d:noColors testing_script.nim
|
||||||
|
|
||||||
|
# With Node.js as a target
|
||||||
|
nim js -d:nodejs -r testing_script.nim
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
|
||||||
|
|
@ -12,3 +12,6 @@ requires "nim >= 0.17.0"
|
||||||
|
|
||||||
task test, "Run tests":
|
task test, "Run tests":
|
||||||
exec "nim c -r tests/test.nim"
|
exec "nim c -r tests/test.nim"
|
||||||
|
|
||||||
|
task testjs, "Run tests on Node.js":
|
||||||
|
exec "nim js -d:nodejs -r tests/test.nim"
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,10 @@ import unicode
|
||||||
import strutils except toLower
|
import strutils except toLower
|
||||||
import tables
|
import tables
|
||||||
import typetraits
|
import typetraits
|
||||||
when not defined(ECMAScript):
|
when defined(ECMAScript):
|
||||||
|
const noColors = true
|
||||||
|
else:
|
||||||
|
const noColors = defined(noColors)
|
||||||
import terminal
|
import terminal
|
||||||
import einheit/utils
|
import einheit/utils
|
||||||
|
|
||||||
|
|
@ -544,7 +547,7 @@ macro testSuite*(head: untyped, body: untyped): untyped =
|
||||||
try:
|
try:
|
||||||
testCall
|
testCall
|
||||||
when defined(quiet):
|
when defined(quiet):
|
||||||
when defined(noColors):
|
when noColors:
|
||||||
stdout.write(".")
|
stdout.write(".")
|
||||||
else:
|
else:
|
||||||
setForegroundColor(fgGreen)
|
setForegroundColor(fgGreen)
|
||||||
|
|
@ -555,7 +558,7 @@ macro testSuite*(head: untyped, body: untyped): untyped =
|
||||||
if self.lastTestFailed:
|
if self.lastTestFailed:
|
||||||
okStr = "\l" & okStr
|
okStr = "\l" & okStr
|
||||||
|
|
||||||
when not defined(noColors):
|
when not noColors:
|
||||||
styledEcho(styleBright, fgGreen, okStr,
|
styledEcho(styleBright, fgGreen, okStr,
|
||||||
fgWhite, " ", self.currentTestName)
|
fgWhite, " ", self.currentTestName)
|
||||||
else:
|
else:
|
||||||
|
|
@ -567,14 +570,14 @@ macro testSuite*(head: untyped, body: untyped): untyped =
|
||||||
let e = (ref TestAssertError)(getCurrentException())
|
let e = (ref TestAssertError)(getCurrentException())
|
||||||
|
|
||||||
when defined(quiet):
|
when defined(quiet):
|
||||||
when defined(noColors):
|
when noColors:
|
||||||
stdout.write("F")
|
stdout.write("F")
|
||||||
else:
|
else:
|
||||||
setForegroundColor(fgRed)
|
setForegroundColor(fgRed)
|
||||||
writeStyled("F", {styleBright})
|
writeStyled("F", {styleBright})
|
||||||
setForegroundColor(fgWhite)
|
setForegroundColor(fgWhite)
|
||||||
else:
|
else:
|
||||||
when not defined(noColors):
|
when not noColors:
|
||||||
styledEcho(styleBright,
|
styledEcho(styleBright,
|
||||||
fgRed, "\l[Failed]",
|
fgRed, "\l[Failed]",
|
||||||
fgWhite, " ", self.currentTestName)
|
fgWhite, " ", self.currentTestName)
|
||||||
|
|
@ -588,7 +591,7 @@ macro testSuite*(head: untyped, body: untyped): untyped =
|
||||||
filename = e.fileName
|
filename = e.fileName
|
||||||
vals = e.valTable
|
vals = e.valTable
|
||||||
|
|
||||||
when not defined(noColors):
|
when not noColors:
|
||||||
styledEcho(styleDim, fgWhite, " Condition: $2($1)\l".format(snip, name), " Where:")
|
styledEcho(styleDim, fgWhite, " Condition: $2($1)\l".format(snip, name), " Where:")
|
||||||
for k, v in vals.pairs:
|
for k, v in vals.pairs:
|
||||||
styledEcho(styleDim, fgCyan, " ", k,
|
styledEcho(styleDim, fgCyan, " ", k,
|
||||||
|
|
@ -742,7 +745,7 @@ proc printRunning(suite: TestSuite) =
|
||||||
ticks &= "-"
|
ticks &= "-"
|
||||||
|
|
||||||
when not defined(quiet):
|
when not defined(quiet):
|
||||||
when not defined(noColors):
|
when not noColors:
|
||||||
styledEcho(styleBright,
|
styledEcho(styleBright,
|
||||||
fgYellow, "\l"&ticks,
|
fgYellow, "\l"&ticks,
|
||||||
fgYellow, "\l\l[Running]",
|
fgYellow, "\l\l[Running]",
|
||||||
|
|
@ -753,16 +756,17 @@ proc printRunning(suite: TestSuite) =
|
||||||
|
|
||||||
|
|
||||||
proc printPassedTests(suite: TestSuite) =
|
proc printPassedTests(suite: TestSuite) =
|
||||||
# Output red if tests didn't pass, green otherwise
|
when not noColors:
|
||||||
var color = fgGreen
|
# Output red if tests didn't pass, green otherwise
|
||||||
|
var color = fgGreen
|
||||||
|
|
||||||
if suite.testsPassed != suite.numTests:
|
if suite.testsPassed != suite.numTests:
|
||||||
color = fgRed
|
color = fgRed
|
||||||
|
|
||||||
var passedStr = "[" & $suite.testsPassed & "/" & $suite.numTests & "]"
|
var passedStr = "[" & $suite.testsPassed & "/" & $suite.numTests & "]"
|
||||||
|
|
||||||
when not defined(quiet):
|
when not defined(quiet):
|
||||||
when not defined(noColors):
|
when not noColors:
|
||||||
styledEcho(styleBright, color,
|
styledEcho(styleBright, color,
|
||||||
"\l", passedStr,
|
"\l", passedStr,
|
||||||
fgWhite, " tests passed for ", suite.name, ".")
|
fgWhite, " tests passed for ", suite.name, ".")
|
||||||
|
|
@ -770,15 +774,16 @@ proc printPassedTests(suite: TestSuite) =
|
||||||
echo "\l$1 tests passed for $2.".format(passedStr, suite.name)
|
echo "\l$1 tests passed for $2.".format(passedStr, suite.name)
|
||||||
|
|
||||||
proc printSummary(totalTestsPassed: int, totalTests: int) =
|
proc printSummary(totalTestsPassed: int, totalTests: int) =
|
||||||
var summaryColor = fgGreen
|
when not noColors:
|
||||||
|
var summaryColor = fgGreen
|
||||||
|
|
||||||
if totalTestsPassed != totalTests:
|
if totalTestsPassed != totalTests:
|
||||||
summaryColor = fgRed
|
summaryColor = fgRed
|
||||||
|
|
||||||
var passedStr = "[" & $totalTestsPassed & "/" & $totalTests & "]"
|
var passedStr = "[" & $totalTestsPassed & "/" & $totalTests & "]"
|
||||||
|
|
||||||
when defined(quiet):
|
when defined(quiet):
|
||||||
when not defined(noColors):
|
when not noColors:
|
||||||
styledEcho(styleBright, summaryColor,
|
styledEcho(styleBright, summaryColor,
|
||||||
"\l\l", passedStr,
|
"\l\l", passedStr,
|
||||||
fgWhite, " tests passed.")
|
fgWhite, " tests passed.")
|
||||||
|
|
@ -795,7 +800,7 @@ proc printSummary(totalTestsPassed: int, totalTests: int) =
|
||||||
for i in 0..<numTicks:
|
for i in 0..<numTicks:
|
||||||
ticks &= "-"
|
ticks &= "-"
|
||||||
|
|
||||||
when not defined(noColors):
|
when not noColors:
|
||||||
styledEcho(styleBright,
|
styledEcho(styleBright,
|
||||||
fgYellow, "\l$1\l".format(ticks),
|
fgYellow, "\l$1\l".format(ticks),
|
||||||
fgYellow, "\l[Summary]")
|
fgYellow, "\l[Summary]")
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,22 @@ when defined(windows):
|
||||||
|
|
||||||
return (rows.int, cols.int)
|
return (rows.int, cols.int)
|
||||||
|
|
||||||
|
elif defined(ECMAScript) and defined(nodejs):
|
||||||
|
type
|
||||||
|
StreamObj {.importc.} = object
|
||||||
|
columns: int
|
||||||
|
rows: int
|
||||||
|
|
||||||
|
ProcessObj {.importc.} = object
|
||||||
|
stdout: ref StreamObj
|
||||||
|
|
||||||
|
var
|
||||||
|
process {.importc, nodecl.}: ref ProcessObj
|
||||||
|
|
||||||
|
proc getTermSize*(): (int, int) =
|
||||||
|
let t = process.stdout
|
||||||
|
return (t.rows, t.columns)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
import posix
|
import posix
|
||||||
type
|
type
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue