A unit-test extracted from some documentation.

A docunit is extracted from the code-blocks of mdocs. Each mdoc can contains more than one docunit, and a single docunit can be made of more that a single code-block.

Introduced properties

private var _block: String

nitc :: DocUnit :: _block

The text of the code to execute.
private var _columns: Array[Int]

nitc :: DocUnit :: _columns

For each line in block, the associated column in the mdoc
private var _is_compiled: Bool

nitc :: DocUnit :: _is_compiled

Was test_file successfully compiled?
private var _lines: Array[Int]

nitc :: DocUnit :: _lines

For each line in block, the associated line in the mdoc
private var _location: Location

nitc :: DocUnit :: _location

The location of the whole docunit.
private var _mdoc: MDoc

nitc :: DocUnit :: _mdoc

The doc that contains self
private var _number: Int

nitc :: DocUnit :: _number

The numbering of self in mdoc (starting with 0)
private var _test_arg: nullable Int

nitc :: DocUnit :: _test_arg

The command-line argument to use when executing the test, if any.
private var _test_file: nullable String

nitc :: DocUnit :: _test_file

The generated Nit source file that contains the unit-test
private var _xml_name: String

nitc :: DocUnit :: _xml_name

fun block: String

nitc :: DocUnit :: block

The text of the code to execute.
protected fun block=(block: String)

nitc :: DocUnit :: block=

The text of the code to execute.
fun columns: Array[Int]

nitc :: DocUnit :: columns

For each line in block, the associated column in the mdoc
protected fun columns=(columns: Array[Int])

nitc :: DocUnit :: columns=

For each line in block, the associated column in the mdoc
init defaultinit(mdoc: MDoc, number: Int, block: String, xml_classname: String, xml_name: String)

nitc :: DocUnit :: defaultinit

fun is_compiled: Bool

nitc :: DocUnit :: is_compiled

Was test_file successfully compiled?
protected fun is_compiled=(is_compiled: Bool)

nitc :: DocUnit :: is_compiled=

Was test_file successfully compiled?
fun lines: Array[Int]

nitc :: DocUnit :: lines

For each line in block, the associated line in the mdoc
protected fun lines=(lines: Array[Int])

nitc :: DocUnit :: lines=

For each line in block, the associated line in the mdoc
protected fun location=(location: Location)

nitc :: DocUnit :: location=

The location of the whole docunit.
fun mdoc: MDoc

nitc :: DocUnit :: mdoc

The doc that contains self
protected fun mdoc=(mdoc: MDoc)

nitc :: DocUnit :: mdoc=

The doc that contains self
fun number: Int

nitc :: DocUnit :: number

The numbering of self in mdoc (starting with 0)
protected fun number=(number: Int)

nitc :: DocUnit :: number=

The numbering of self in mdoc (starting with 0)
fun real_location(ast_location: Location): Location

nitc :: DocUnit :: real_location

Compute the real location of a node on the ast based on mdoc.location
fun test_arg: nullable Int

nitc :: DocUnit :: test_arg

The command-line argument to use when executing the test, if any.
protected fun test_arg=(test_arg: nullable Int)

nitc :: DocUnit :: test_arg=

The command-line argument to use when executing the test, if any.
fun test_file: nullable String

nitc :: DocUnit :: test_file

The generated Nit source file that contains the unit-test
protected fun test_file=(test_file: nullable String)

nitc :: DocUnit :: test_file=

The generated Nit source file that contains the unit-test
protected fun xml_classname=(xml_classname: String)

nitc :: DocUnit :: xml_classname=

protected fun xml_name=(xml_name: String)

nitc :: DocUnit :: xml_name=

Redefined properties

redef type SELF: DocUnit

nitc $ DocUnit :: SELF

Type of this instance, automatically specialized in every class
redef fun full_name: String

nitc $ DocUnit :: full_name

The name of the unit to show in messages
redef fun location: Location

nitc $ DocUnit :: location

The location of the whole docunit.
redef fun to_xml: HTMLTag

nitc $ DocUnit :: to_xml

Return a <testcase> XML node in format compatible with Jenkins unit tests.
redef fun xml_classname: String

nitc $ DocUnit :: xml_classname

The classname attribute of the XML format.
redef fun xml_name: String

nitc $ DocUnit :: xml_name

The name attribute of the XML format.

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
private var _block: String

nitc :: DocUnit :: _block

The text of the code to execute.
private var _columns: Array[Int]

nitc :: DocUnit :: _columns

For each line in block, the associated column in the mdoc
private var _error: nullable String

nitc :: UnitTest :: _error

Error message occurred during test-case execution (or compilation).
private var _error_location: nullable Location

nitc :: UnitTest :: _error_location

The location where the error occurred, if it makes sense.
private var _info: nullable String

nitc :: UnitTest :: _info

Additional noteworthy information when a test success.
private var _is_compiled: Bool

nitc :: DocUnit :: _is_compiled

Was test_file successfully compiled?
private var _is_done: Bool

nitc :: UnitTest :: _is_done

Flag that indicates if the unit test was compiled/run.
private var _lines: Array[Int]

nitc :: DocUnit :: _lines

For each line in block, the associated line in the mdoc
private var _location: Location

nitc :: DocUnit :: _location

The location of the whole docunit.
private var _mdoc: MDoc

nitc :: DocUnit :: _mdoc

The doc that contains self
private var _number: Int

nitc :: DocUnit :: _number

The numbering of self in mdoc (starting with 0)
private var _raw_output: nullable String

nitc :: UnitTest :: _raw_output

The raw output of the execution (or compilation)
private var _real_time: Float

nitc :: UnitTest :: _real_time

Time for the execution, in seconds
private var _test_arg: nullable Int

nitc :: DocUnit :: _test_arg

The command-line argument to use when executing the test, if any.
private var _test_file: nullable String

nitc :: DocUnit :: _test_file

The generated Nit source file that contains the unit-test
private var _was_exec: Bool

nitc :: UnitTest :: _was_exec

Was the test case executed at least once?
private var _xml_name: String

nitc :: DocUnit :: _xml_name

fun block: String

nitc :: DocUnit :: block

The text of the code to execute.
protected fun block=(block: String)

nitc :: DocUnit :: block=

The text of the code to execute.
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun columns: Array[Int]

nitc :: DocUnit :: columns

For each line in block, the associated column in the mdoc
protected fun columns=(columns: Array[Int])

nitc :: DocUnit :: columns=

For each line in block, the associated column in the mdoc
init defaultinit(mdoc: MDoc, number: Int, block: String, xml_classname: String, xml_name: String)

nitc :: DocUnit :: defaultinit

fun error: nullable String

nitc :: UnitTest :: error

Error message occurred during test-case execution (or compilation).
fun error=(error: nullable String)

nitc :: UnitTest :: error=

Error message occurred during test-case execution (or compilation).
fun error_location: nullable Location

nitc :: UnitTest :: error_location

The location where the error occurred, if it makes sense.
fun error_location=(error_location: nullable Location)

nitc :: UnitTest :: error_location=

The location where the error occurred, if it makes sense.
abstract fun full_name: String

nitc :: UnitTest :: full_name

The name of the unit to show in messages
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
fun info: nullable String

nitc :: UnitTest :: info

Additional noteworthy information when a test success.
protected fun info=(info: nullable String)

nitc :: UnitTest :: info=

Additional noteworthy information when a test success.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
fun is_compiled: Bool

nitc :: DocUnit :: is_compiled

Was test_file successfully compiled?
protected fun is_compiled=(is_compiled: Bool)

nitc :: DocUnit :: is_compiled=

Was test_file successfully compiled?
fun is_done: Bool

nitc :: UnitTest :: is_done

Flag that indicates if the unit test was compiled/run.
fun is_done=(is_done: Bool)

nitc :: UnitTest :: is_done=

Flag that indicates if the unit test was compiled/run.
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun lines: Array[Int]

nitc :: DocUnit :: lines

For each line in block, the associated line in the mdoc
protected fun lines=(lines: Array[Int])

nitc :: DocUnit :: lines=

For each line in block, the associated line in the mdoc
abstract fun location: Location

nitc :: UnitTest :: location

The location of the unit test to show in messages.
protected fun location=(location: Location)

nitc :: DocUnit :: location=

The location of the whole docunit.
fun mdoc: MDoc

nitc :: DocUnit :: mdoc

The doc that contains self
protected fun mdoc=(mdoc: MDoc)

nitc :: DocUnit :: mdoc=

The doc that contains self
private intern fun native_class_name: CString

core :: Object :: native_class_name

The class name of the object in CString format.
fun number: Int

nitc :: DocUnit :: number

The numbering of self in mdoc (starting with 0)
protected fun number=(number: Int)

nitc :: DocUnit :: number=

The numbering of self in mdoc (starting with 0)
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun raw_output: nullable String

nitc :: UnitTest :: raw_output

The raw output of the execution (or compilation)
fun raw_output=(raw_output: nullable String)

nitc :: UnitTest :: raw_output=

The raw output of the execution (or compilation)
fun real_location(ast_location: Location): Location

nitc :: DocUnit :: real_location

Compute the real location of a node on the ast based on mdoc.location
fun real_time: Float

nitc :: UnitTest :: real_time

Time for the execution, in seconds
fun real_time=(real_time: Float)

nitc :: UnitTest :: real_time=

Time for the execution, in seconds
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
fun status_tag(color: nullable Bool): String

nitc :: UnitTest :: status_tag

A colorful [OK] or [KO].
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
fun test_arg: nullable Int

nitc :: DocUnit :: test_arg

The command-line argument to use when executing the test, if any.
protected fun test_arg=(test_arg: nullable Int)

nitc :: DocUnit :: test_arg=

The command-line argument to use when executing the test, if any.
fun test_file: nullable String

nitc :: DocUnit :: test_file

The generated Nit source file that contains the unit-test
protected fun test_file=(test_file: nullable String)

nitc :: DocUnit :: test_file=

The generated Nit source file that contains the unit-test
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
fun to_screen(more_message: nullable String, color: nullable Bool): String

nitc :: UnitTest :: to_screen

The full (color) description of the test-case.
fun to_xml: HTMLTag

nitc :: UnitTest :: to_xml

Return a <testcase> XML node in format compatible with Jenkins unit tests.
fun was_exec: Bool

nitc :: UnitTest :: was_exec

Was the test case executed at least once?
fun was_exec=(was_exec: Bool)

nitc :: UnitTest :: was_exec=

Was the test case executed at least once?
abstract fun xml_classname: String

nitc :: UnitTest :: xml_classname

The classname attribute of the XML format.
protected fun xml_classname=(xml_classname: String)

nitc :: DocUnit :: xml_classname=

abstract fun xml_name: String

nitc :: UnitTest :: xml_name

The name attribute of the XML format.
protected fun xml_name=(xml_name: String)

nitc :: DocUnit :: xml_name=

package_diagram nitc::DocUnit DocUnit nitc::UnitTest UnitTest nitc::DocUnit->nitc::UnitTest core::Object Object nitc::UnitTest->core::Object ...core::Object ... ...core::Object->core::Object

Ancestors

interface Object

core :: Object

The root of the class hierarchy.

Parents

abstract class UnitTest

nitc :: UnitTest

A unit test is an elementary test discovered, run and reported by nitunit.

Class definitions

nitc $ DocUnit
# A unit-test extracted from some documentation.
#
# A docunit is extracted from the code-blocks of mdocs.
# Each mdoc can contains more than one docunit, and a single docunit can be made of more that a single code-block.
class DocUnit
	super UnitTest

	# The doc that contains self
	var mdoc: MDoc

	# The numbering of self in mdoc (starting with 0)
	var number: Int

	# The generated Nit source file that contains the unit-test
	#
	# Note that a same generated file can be used for multiple tests.
	# See `test_arg` that is used to distinguish them
	var test_file: nullable String = null

	#  Was `test_file` successfully compiled?
	var is_compiled = false

	# The command-line argument to use when executing the test, if any.
	var test_arg: nullable Int = null

	redef fun full_name do
		var mentity = mdoc.original_mentity
		if mentity != null then
			var res = mentity.full_name
			if number > 1 then
				res += "#{number}"
			end
			return res
		else
			return xml_classname + "." + xml_name
		end
	end

	# The text of the code to execute.
	#
	# This is the verbatim content on one, or more, code-blocks from `mdoc`
	var block: String

	# For each line in `block`, the associated line in the mdoc
	#
	# Is used to give precise locations
	var lines = new Array[Int]

	# For each line in `block`, the associated column in the mdoc
	#
	# Is used to give precise locations
	var columns = new Array[Int]

	# The location of the whole docunit.
	#
	# If `self` is made of multiple code-blocks, then the location
	# starts at the first code-books and finish at the last one, thus includes anything between.
	redef var location is lazy do
		return new Location(mdoc.location.file, lines.first, lines.last+1, columns.first+1, 0)
	end

	# Compute the real location of a node on the `ast` based on `mdoc.location`
	#
	# The result is basically: ast_location + markdown location of the piece + mdoc.location
	#
	# The fun is that a single docunit can be made of various pieces of code blocks.
	fun real_location(ast_location: Location): Location
	do
		var mdoc = self.mdoc

		var res = new Location(mdoc.location.file,
			lines[ast_location.line_start-1],
			lines[ast_location.line_end-1],
			columns[ast_location.line_start-1] + ast_location.column_start,
			columns[ast_location.line_end-1] + ast_location.column_end)

		return res
	end

	redef fun to_xml
	do
		var res = super
		res.open("system-out").append(block)
		return res
	end

	redef var xml_classname
	redef var xml_name
end
src/testing/testing_doc.nit:460,1--548,3