summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2011-11-10 04:39:46 +0200
committerZahary Karadjov <zahary@gmail.com>2011-11-10 04:39:46 +0200
commitda4076e0b7d3336d28893feba1399028abdbd52e (patch)
tree61cc0f7f79a7a004b770852492c0fc6bd2239e64
parent489340658ea855d01de853d3c95c928d6e1b9f86 (diff)
downloadNim-da4076e0b7d3336d28893feba1399028abdbd52e.tar.gz
when running unit tests, the tester will print only failures using colorless output (this should be better for nimbuild)
-rw-r--r--examples/tunit.nim (renamed from tests/accept/run/tunit.nim)0
-rw-r--r--lib/pure/unittest.nim32
-rwxr-xr-xtests/tester.nim3
3 files changed, 27 insertions, 8 deletions
diff --git a/tests/accept/run/tunit.nim b/examples/tunit.nim
index d0e975119..d0e975119 100644
--- a/tests/accept/run/tunit.nim
+++ b/examples/tunit.nim
diff --git a/lib/pure/unittest.nim b/lib/pure/unittest.nim
index 6fee618b9..e2906dd1a 100644
--- a/lib/pure/unittest.nim
+++ b/lib/pure/unittest.nim
@@ -17,16 +17,17 @@
 ## It is loosely based on C++'s boost.test and Haskell's QuickTest

 

 import

-  macros, terminal

+  macros, terminal, os

 

 type

   TTestStatus* = enum OK, FAILED

   TOutputLevel* = enum PRINT_ALL, PRINT_FAILURES, PRINT_NONE

-  

+

 var 

   # XXX: These better be thread-local

-  AbortOnError* = false

-  OutputLevel* = PRINT_ALL

+  AbortOnError*: bool

+  OutputLevel*: TOutputLevel

+  ColorOutput*: bool

   

   checkpoints: seq[string] = @[]

 

@@ -52,7 +53,11 @@ proc testDone(name: string, s: TTestStatus) =
 

   if OutputLevel != PRINT_NONE and (OutputLevel == PRINT_ALL or s == FAILED):

     var color = (if s == OK: fgGreen else: fgRed)

-    styledEcho styleBright, color, "[", $s, "] ", fgWhite, name, "\n"

+    

+    if ColorOutput:

+      styledEcho styleBright, color, "[", $s, "] ", fgWhite, name, "\n"

+    else:

+      echo "[", $s, "] ", name, "\n"

   

 template test*(name: expr, body: stmt): stmt =

   bind shouldRun, checkpoints, testDone

@@ -92,8 +97,6 @@ macro check*(conditions: stmt): stmt =
  

     result = getAst(rewrite(e, e.lineinfo, e.toStrLit))

   

-  echo conditions.lispRepr

-

   case conditions.kind

   of nnkCall, nnkCommand, nnkMacroStmt:

     case conditions[1].kind

@@ -133,7 +136,8 @@ macro check*(conditions: stmt): stmt =
       result = standardRewrite(conditions[1])

 

   else:

-    error conditions.lineinfo & ": Malformed check statement:"

+    var ast = conditions.treeRepr

+    error conditions.lineinfo & ": Malformed check statement:\n" & ast

 

 template require*(conditions: stmt): stmt =

   block:

@@ -158,3 +162,15 @@ macro expect*(exp: stmt): stmt =
 

   result = getAst(expectBody(errorTypes, exp.lineinfo, body))

 

+

+## Reading settings

+var envOutLvl = os.getEnv("NIMTEST_OUTPUT_LVL").string

+

+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/tests/tester.nim b/tests/tester.nim
index 3f563de4a..1b88f9292 100755
--- a/tests/tester.nim
+++ b/tests/tester.nim
@@ -391,6 +391,9 @@ proc outputJSON(reject, compile, run: TResults) =
   writeFile(jsonFile, s)
 
 proc main() =
+  os.putenv "NIMTEST_NO_COLOR", "1"
+  os.putenv "NIMTEST_OUTPUT_LVL", "PRINT_FAILURES"
+
   const
     compileJson = "compile.json"
     runJson = "run.json"