nitunit: add time information
authorJean Privat <jean@pryen.org>
Sat, 11 Jun 2016 01:45:27 +0000 (21:45 -0400)
committerJean Privat <jean@pryen.org>
Sat, 11 Jun 2016 01:45:27 +0000 (21:45 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/testing/testing_base.nit
src/testing/testing_doc.nit
src/testing/testing_suite.nit

index 36ce1f9..a6acc79 100644 (file)
@@ -201,6 +201,9 @@ abstract class UnitTest
        # Additional noteworthy information when a test success.
        var info: nullable String = null
 
+       # Time for the execution, in seconds
+       var real_time: Float = 0.0 is writable
+
        # A colorful `[OK]` or `[KO]`.
        fun status_tag(color: nullable Bool): String do
                color = color or else true
@@ -252,6 +255,7 @@ abstract class UnitTest
                var tc = new HTMLTag("testcase")
                tc.attr("classname", xml_classname)
                tc.attr("name", xml_name)
+               tc.attr("time", real_time.to_s)
                var error = self.error
                if error != null then
                        if was_exec then
index 75e0830..1cdd10a 100644 (file)
@@ -19,6 +19,7 @@ private import parser_util
 import testing_base
 import markdown
 import html
+import realtime
 
 # Extractor, Executor and Reporter for the tests in a module
 class NitUnitExecutor
@@ -194,7 +195,9 @@ class NitUnitExecutor
                var file = du.test_file.as(not null)
                var i = du.test_arg.as(not null)
                toolcontext.info("Execute doc-unit {du.full_name} in {file} {i}", 1)
+               var clock = new Clock
                var res2 = toolcontext.safe_exec("{file.to_program_name}.bin {i} >'{file}.out1' 2>&1 </dev/null")
+               du.real_time = clock.total
                du.was_exec = true
 
                var content = "{file}.out1".to_path.read_all
@@ -225,7 +228,9 @@ class NitUnitExecutor
                var res = compile_unitfile(file)
                var res2 = 0
                if res == 0 then
+                       var clock = new Clock
                        res2 = toolcontext.safe_exec("{file.to_program_name}.bin >'{file}.out1' 2>&1 </dev/null")
+                       du.real_time = clock.total
                        du.was_exec = true
                end
 
index f102c6c..e0ab351 100644 (file)
@@ -18,6 +18,7 @@ module testing_suite
 import testing_base
 import html
 private import annotation
+private import realtime
 
 redef class ToolContext
        # --pattern
@@ -257,7 +258,10 @@ class TestCase
                var method_name = test_method.name
                var test_file = test_suite.test_file
                var res_name = "{test_file}_{method_name.escape_to_c}"
+               var clock = new Clock
                var res = toolcontext.safe_exec("{test_file}.bin {method_name} > '{res_name}.out1' 2>&1 </dev/null")
+               real_time = clock.total
+
                var raw_output = "{res_name}.out1".to_path.read_all
                self.raw_output = raw_output
                # set test case result