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

Property definitions

nitc :: testing_base $ ToolContext :: show_unit_status
	# 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
src/testing/testing_base.nit:100,2--144,4