diff options
-rwxr-xr-x | lib/pure/times.nim | 5 | ||||
-rw-r--r-- | lib/pure/unittest.nim | 39 | ||||
-rwxr-xr-x | lib/system/jssys.nim | 2 | ||||
-rw-r--r-- | tests/js/tunittests.nim | 5 |
4 files changed, 36 insertions, 15 deletions
diff --git a/lib/pure/times.nim b/lib/pure/times.nim index 1d6ca2646..6a73303d9 100755 --- a/lib/pure/times.nim +++ b/lib/pure/times.nim @@ -78,6 +78,7 @@ elif defined(JS): getUTCMinutes: proc (): int getUTCMonth: proc (): int getUTCSeconds: proc (): int + getUTCDay: proc (): int getYear: proc (): int parse: proc (s: cstring): TTime setDate: proc (x: int) @@ -427,7 +428,7 @@ when not defined(JS): proc cpuTime(): float = result = toFloat(int(clock())) / toFloat(clocksPerSec) -else: +elif defined(JS): proc newDate(): TTime {.importc: "new Date", nodecl.} proc getTime(): TTime = return newDate() @@ -452,7 +453,7 @@ else: result.monthday = t.getUTCDate() result.month = TMonth(t.getUTCMonth()) result.year = t.getUTCFullYear() - result.weekday = weekDays[t.getDay()] + result.weekday = weekDays[t.getUTCDay()] result.yearday = 0 proc TimeInfoToTime*(timeInfo: TTimeInfo): TTime = diff --git a/lib/pure/unittest.nim b/lib/pure/unittest.nim index fce84bea4..71f4d498b 100644 --- a/lib/pure/unittest.nim +++ b/lib/pure/unittest.nim @@ -17,7 +17,13 @@ ## It is loosely based on C++'s boost.test and Haskell's QuickTest import - macros, terminal, os + macros + +when defined(stdout): + import os + +when not defined(ECMAScript): + import terminal type TTestStatus* = enum OK, FAILED @@ -52,12 +58,15 @@ proc testDone(name: string, s: TTestStatus) = program_result += 1 if OutputLevel != PRINT_NONE and (OutputLevel == PRINT_ALL or s == FAILED): - var color = (if s == OK: fgGreen else: fgRed) - - if ColorOutput: - styledEcho styleBright, color, "[", $s, "] ", fgWhite, name, "\n" + template rawPrint() = echo("[", $s, "] ", name, "\n") + when not defined(ECMAScript): + if ColorOutput and not defined(ECMAScript): + var color = (if s == OK: fgGreen else: fgRed) + styledEcho styleBright, color, "[", $s, "] ", fgWhite, name, "\n" + else: + rawPrint() else: - echo "[", $s, "] ", name, "\n" + rawPrint() template test*(name: expr, body: stmt): stmt {.immediate, dirty.} = bind shouldRun, checkpoints, testDone @@ -87,7 +96,8 @@ template fail* = for msg in items(checkpoints): echo msg - if AbortOnError: quit(1) + when not defined(ECMAScript): + if AbortOnError: quit(1) TestStatusIMPL = FAILED checkpoints = @[] @@ -171,14 +181,19 @@ macro expect*(exceptions: varargs[expr], body: stmt): stmt {.immediate.} = result = getAst(expectBody(errorTypes, exp.lineinfo, body)) -## Reading settings -var envOutLvl = os.getEnv("NIMTEST_OUTPUT_LVL").string +when defined(stdout): + ## Reading settings + var envOutLvl = os.getEnv("NIMTEST_OUTPUT_LVL").string + + AbortOnError = existsEnv("NIMTEST_ABORT_ON_ERROR") + ColorOutput = not existsEnv("NIMTEST_NO_COLOR") + +else: + var envOutLvl = "" # TODO + ColorOutput = false if envOutLvl.len > 0: for opt in countup(low(TOutputLevel), high(TOutputLevel)): if $opt == envOutLvl: OutputLevel = opt break - -AbortOnError = existsEnv("NIMTEST_ABORT_ON_ERROR") -ColorOutput = not existsEnv("NIMTEST_NO_COLOR") diff --git a/lib/system/jssys.nim b/lib/system/jssys.nim index 6040fdf53..789e39d6d 100755 --- a/lib/system/jssys.nim +++ b/lib/system/jssys.nim @@ -42,7 +42,7 @@ proc nimCharToStr(x: char): string {.compilerproc.} = result = newString(1) result[0] = x -proc getCurrentExceptionMsg(): string = +proc getCurrentExceptionMsg*(): string = if excHandler != nil: return $excHandler.exc.msg return "" diff --git a/tests/js/tunittests.nim b/tests/js/tunittests.nim new file mode 100644 index 000000000..af38cd9b9 --- /dev/null +++ b/tests/js/tunittests.nim @@ -0,0 +1,5 @@ +import unittest + +suite "Bacon": + test ">:)": + check(true == true) |