nitunit: add --no-time to avoid time and improve reproductible results
authorJean Privat <jean@pryen.org>
Sat, 11 Jun 2016 20:04:01 +0000 (16:04 -0400)
committerJean Privat <jean@pryen.org>
Sat, 11 Jun 2016 20:04:25 +0000 (16:04 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

share/man/nitunit.md
src/nitunit.nit
src/testing/testing_base.nit
src/testing/testing_doc.nit
src/testing/testing_suite.nit

index 2bec157..73c5b3e 100644 (file)
@@ -331,6 +331,13 @@ If a test-case of a test-suite passes but that some output is generated, then an
 It is expected that the created/updated files are checked since the tests are considered passed.
 A VCS like `git` is often a good tool to check the creation and modification of those files.
 
+### `--no-time`
+Disable time information in XML.
+
+This is used to have reproducible XML results.
+
+This option is automatically activated if `NIT_TESTING` is set.
+
 ## SUITE GENERATION
 
 ### `--gen-suite`
index 996fe27..f58b916 100644 (file)
@@ -59,6 +59,11 @@ if toolcontext.opt_gen_unit.value then
        exit(0)
 end
 
+# When testing `nitunit`, disable time.
+if "NIT_TESTING".environ != "" then
+       toolcontext.opt_no_time.value = true
+end
+
 "NIT_TESTING".setenv("true")
 "NIT_TESTING_ID".setenv(pid.to_s)
 "SRAND".setenv("0")
index 592d5f0..6281977 100644 (file)
@@ -31,6 +31,8 @@ redef class ToolContext
        var opt_noact = new OptionBool("Does not compile and run tests", "--no-act")
        # opt --nitc
        var opt_nitc = new OptionString("nitc compiler to use", "--nitc")
+       # opt --no-time
+       var opt_no_time = new OptionBool("Disable time information in XML", "--no-time")
 
        # Working directory for testing.
        fun test_dir: String do
index 1180bff..b3e9c44 100644 (file)
@@ -197,7 +197,7 @@ class NitUnitExecutor
                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
+               if not toolcontext.opt_no_time.value then du.real_time = clock.total
                du.was_exec = true
 
                var content = "{file}.out1".to_path.read_all
@@ -230,7 +230,7 @@ class NitUnitExecutor
                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
+                       if not toolcontext.opt_no_time.value then du.real_time = clock.total
                        du.was_exec = true
                end
 
index 69478cd..60265ab 100644 (file)
@@ -261,7 +261,7 @@ class TestCase
                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
+               if not toolcontext.opt_no_time.value then real_time = clock.total
 
                var raw_output = "{res_name}.out1".to_path.read_all
                self.raw_output = raw_output