Property definitions

nitc $ UnitTest :: defaultinit
# A unit test is an elementary test discovered, run and reported by nitunit.
#
# This class factorizes `DocUnit` and `TestCase`.
abstract class UnitTest
	# The name of the unit to show in messages
	fun full_name: String is abstract

	# The location of the unit test to show in messages.
	fun location: Location is abstract

	# Flag that indicates if the unit test was compiled/run.
	var is_done: Bool = false is writable

	# Error message occurred during test-case execution (or compilation).
	#
	# e.g.: `Runtime Error`
	var error: nullable String = null is writable

	# Was the test case executed at least once?
	#
	# This will indicate the status of the test (failture or error)
	var was_exec = false is writable

	# The raw output of the execution (or compilation)
	#
	# It merges the standard output and error output
	var raw_output: nullable String = null is writable

	# The location where the error occurred, if it makes sense.
	var error_location: nullable Location = null is writable

	# 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
		if not is_done then
			return "[  ]"
		else if error != null then
			var res = "[KO]"
			if color then res = res.red.bold
			return res
		else
			var res = "[OK]"
			if color then res = res.green.bold
			return res
		end
	end

	# The full (color) description of the test-case.
	#
	# `more message`, if any, is added after the error message.
	fun to_screen(more_message: nullable String, color: nullable Bool): String do
		color = color or else true
		var res
		var error = self.error
		if error != null then
			if more_message != null then error += " " + more_message
			var loc = error_location or else location
			if color then
				res = "{status_tag(color)} {full_name}\n     {loc.to_s.yellow}: {error}\n{loc.colored_line("1;31")}"
			else
				res = "{status_tag(color)} {full_name}\n     {loc}: {error}"
			end
			var output = self.raw_output
			if output != null then
				res += "\n     Output\n\t{output.chomp.replace("\n", "\n\t")}\n"
			end
		else
			res = "{status_tag(color)} {full_name}"
			if more_message != null then res += more_message
			var info = self.info
			if info != null then
				res += "\n     {info}"
			end
		end
		return res
	end

	# Return a `<testcase>` XML node in format compatible with Jenkins unit tests.
	fun to_xml: HTMLTag do
		var tc = new HTMLTag("testcase")
		tc.attr("classname", xml_classname)
		tc.attr("name", xml_name)
		tc.attr("time", real_time.to_s)

		var output = self.raw_output
		if output != null then output = output.trunc(8192).filter_nonprintable
		var error = self.error
		if error != null then
			var node
			if was_exec then
				node = tc.open("error").attr("message", error)
			else
				node = tc.open("failure").attr("message", error)
			end
			if output != null then
				node.append(output)
			end
		else if output != null then
			tc.open("system-err").append(output)
		end
		return tc
	end

	# The `classname` attribute of the XML format.
	#
	# NOTE: jenkins expects a '.' in the classname attr
	#
	# See to_xml
	fun xml_classname: String is abstract

	# The `name` attribute of the XML format.
	#
	# See to_xml
	fun xml_name: String is abstract
end
src/testing/testing_base.nit:178,1--298,3