+
+ # Show a single-line status to use as a progression.
+ #
+ # If `has_progress_bar` is true, then the output is a progress bar.
+ # The printed 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
+ #
+ # If `has_progress_bar` is false, then only the first and last state is shown
+ fun show_unit_status(name: String, tests: SequenceRead[UnitTest])
+ do
+ var line = "\r\x1B[K==== {name} ["
+ var done = tests.length
+ var fails = 0
+ 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
+ fails += 1
+ end
+ end
+
+ if not has_progress_bar then
+ if done == 0 then
+ print "==== {name} | tests: {tests.length}"
+ end
+ return
+ end
+
+ if done < tests.length then
+ line += "] {done}/{tests.length}"
+ else
+ line += "] tests: {tests.length} "
+ if fails == 0 then
+ line += "OK".green.bold
+ else
+ line += "KO: {fails}".red.bold
+ end
+ end
+ printn "{line}"
+ end
+
+ # Is a progress bar printed?
+ #
+ # true if color (because and non-verbose mode
+ # (because verbose mode messes up with the progress bar).
+ fun has_progress_bar: Bool
+ do
+ return not opt_no_color.value and opt_verbose.value <= 0
+ end
+
+ # Clear the line if `has_progress_bar` (no-op else)
+ fun clear_progress_bar
+ do
+ if has_progress_bar then printn "\r\x1B[K"
+ end
+
+ # Show the full description of the test-case.
+ #
+ # The output honors `--no-color`.
+ #
+ # `more message`, if any, is added after the error message.
+ fun show_unit(test: UnitTest, more_message: nullable String) do
+ print test.to_screen(more_message, not opt_no_color.value)
+ end
+
+ # Set the `NIT_TESTING_PATH` environment variable with `path`.
+ #
+ # If `path == null` then `NIT_TESTING_PATH` is set with the empty string.
+ fun set_testing_path(path: nullable String) do
+ "NIT_TESTING_PATH".setenv(path or else "")
+ end