std.test.Test
class pub Test
A single unit test.
Fields
id
let pub @id: Int
The unique ID of this test.
This ID can be used when you want to create some sort of resource unique to a test, such as a file. This removes the need for manually generating unique names/paths/etc.
name
let pub @name: String
The name of the test as defined by the user.
path
let pub @path: Path
The path to the source file the test is defined in.
line
let pub @line: Int
The line on which the test is defined.
failures
let pub @failures: Array[Failure]
All test failures produced when running the tests.
Static methods
new
Show source codeHide source code
fn pub static new(
id: Int,
name: String,
path: Path,
line: Int,
code: uni fn (mut Test),
) -> Test {
Test(id: id, name: name, path: path, line: line, failures: [], code: code)
}
fn pub static new(id: Int, name: String, path: Path, line: Int, code: uni fn (mut Test)) -> Test
Returns a new Test
.
Instance methods
equal
Show source codeHide source code
fn pub mut equal[T: Equal[ref T] + Format](got: ref T, expected: ref T) {
if got == expected { return }
@failures.push(Failure.new(fmt(got), fmt(expected)))
}
fn pub mut equal[T: Equal[ref T] + Format](got: ref T, expected: ref T)
Asserts that the given arguments are equal to each other.
false
Show source codeHide source code
fn pub mut false(value: Bool) {
if value.false? { return }
@failures.push(Failure.new('true', 'false'))
}
fn pub mut false(value: Bool)
Asserts that the given value is false
.
greater
Show source codeHide source code
fn pub mut greater[T: Compare[T] + Format](got: ref T, minimum: ref T) {
if got > minimum { return }
@failures.push(Failure.new(fmt(got), '> ${fmt(minimum)}'))
}
fn pub mut greater[T: Compare[T] + Format](got: ref T, minimum: ref T)
Asserts that got
is greater than minimum
.
greater_or_equal
Show source codeHide source code
fn pub mut greater_or_equal[T: Compare[T] + Format](
got: ref T,
minimum: ref T,
) {
if got >= minimum { return }
@failures.push(Failure.new(fmt(got), '>= ${fmt(minimum)}'))
}
fn pub mut greater_or_equal[T: Compare[T] + Format](got: ref T, minimum: ref T)
Asserts that got
is greater than or equal to minimum
.
not_equal
Show source codeHide source code
fn pub mut not_equal[T: Equal[ref T] + Format](got: ref T, expected: ref T) {
if got != expected { return }
@failures.push(Failure.new(fmt(got), fmt(expected)))
}
fn pub mut not_equal[T: Equal[ref T] + Format](got: ref T, expected: ref T)
Asserts that the given arguments are not equal to each other.
true
Show source codeHide source code
fn pub mut true(value: Bool) {
if value { return }
@failures.push(Failure.new('false', 'true'))
}
fn pub mut true(value: Bool)
Asserts that the given value is true
.