From 8eb6a52e05dbe0753abcf1dc0110d08054f70784 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Tue, 24 May 2016 20:11:56 -0400 Subject: [PATCH] nitunit: show a progress bar Signed-off-by: Jean Privat --- src/testing/testing_base.nit | 29 +++++++++++++++++++++++++++++ src/testing/testing_doc.nit | 14 ++++++++++++++ src/testing/testing_suite.nit | 15 ++++++++++++++- 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/testing/testing_base.nit b/src/testing/testing_base.nit index 62bf57e..88651ef 100644 --- a/src/testing/testing_base.nit +++ b/src/testing/testing_base.nit @@ -94,6 +94,35 @@ ulimit -t {{{ulimit_usertime}}} 2> /dev/null # # Default: 10 CPU minute var ulimit_usertime = 600 is writable + + # Show a single-line status to use as a progression. + # + # Note that the line starts with `'\r'` and is not ended by a `'\n'`. + # So it is expected that: + # * no other output is printed between two calls + # * the last `show_unit_status` is followed by a new-line + fun show_unit_status(name: String, tests: SequenceRead[UnitTest], more_message: nullable String) + do + var esc = 27.code_point.to_s + var line = "\r{esc}[K* {name} [" + var done = tests.length + for t in tests do + if not t.is_done then + line += " " + done -= 1 + else if t.error == null then + line += ".".green.bold + else + line += "X".red.bold + end + end + line += "] {done}/{tests.length}" + if more_message != null then + line += " " + more_message + end + printn "{line}" + end + end # A unit test is an elementary test discovered, run and reported by nitunit. diff --git a/src/testing/testing_doc.nit b/src/testing/testing_doc.nit index 7419c9f..2465d37 100644 --- a/src/testing/testing_doc.nit +++ b/src/testing/testing_doc.nit @@ -78,15 +78,26 @@ class NitUnitExecutor # All extracted docunits var docunits = new Array[DocUnit] + fun show_status(more_message: nullable String) + do + toolcontext.show_unit_status(name, docunits, more_message) + end + fun mark_done(du: DocUnit) do du.is_done = true + show_status(du.full_name + " " + du.status_tag) end # Execute all the docunits fun run_tests do + if docunits.is_empty then + return + end + var simple_du = new Array[DocUnit] + show_status for du in docunits do # Skip existing errors if du.error != null then @@ -104,6 +115,9 @@ class NitUnitExecutor test_simple_docunits(simple_du) + show_status + print "" + for du in docunits do print du.to_screen end diff --git a/src/testing/testing_suite.nit b/src/testing/testing_suite.nit index 6a10288..bbe9372 100644 --- a/src/testing/testing_suite.nit +++ b/src/testing/testing_suite.nit @@ -132,8 +132,14 @@ class TestSuite # Test to be executed after the whole test suite. var after_module: nullable TestCase = null + fun show_status(more_message: nullable String) + do + toolcontext.show_unit_status("Test-suite of module " + mmodule.full_name, test_cases, more_message) + end + # Execute the test suite fun run do + show_status if not toolcontext.test_dir.file_exists then toolcontext.test_dir.mkdir end @@ -142,7 +148,14 @@ class TestSuite toolcontext.info("Execute test-suite {mmodule.name}", 1) var before_module = self.before_module if not before_module == null then before_module.run - for case in test_cases do case.run + for case in test_cases do + case.run + show_status(case.full_name + " " + case.status_tag) + end + + show_status + print "" + var after_module = self.after_module if not after_module == null then after_module.run for case in test_cases do -- 1.7.9.5