Standard library
Testing
Test registration and assertions for xo test.
Introduction
Test registration and assertions for xo test. Import std/test to bind the module as test. Call free functions as test.name(...). Struct methods use a receiver value.
/ std/test
This page is the package reference for std/test. Private helpers used only by co-located tests are not listed.
Functions
Free functions on test. Each function has a short description, an example, then parameters and return shape.
it
Registers a named test case. body is a zero-arg function run by xo test. Call form: test.it(name, body).
/ std/test
test.it("adds", () {
test.eq(1 + 1, 2)
})Parameters: name: test case name. body: zero-argument function. Returns: None. Registers the case for the runner.
eq
Asserts left deep-equals right; fails the current test otherwise. Call form: test.eq(left, right).
/ std/test
test.it("eq", () {
test.eq(2, 1 + 1)
})Parameters: left: left value. right: right value. Returns: None. Fails the current test on mismatch.
ne
Asserts left is not equal to right. Call form: test.ne(left, right).
/ std/test
test.it("ne", () {
test.ne(1, 2)
})Parameters: left: left value. right: right value. Returns: None. Fails the current test on unexpected equality.
true
Asserts cond is true. Call form: test.true(cond).
/ std/test
test.it("true", () {
test.true(1 == 1)
})Parameters: cond: boolean condition. Returns: None. Fails the current test when cond is false.
false
Asserts cond is false. Call form: test.false(cond).
/ std/test
test.it("false", () {
test.false(1 == 2)
})Parameters: cond: boolean condition. Returns: None. Fails the current test when cond is true.
fail
Fails the current test with message msg. Call form: test.fail(msg).
/ std/test
test.it("fail", () {
test.fail("unreachable")
})Parameters: msg: failure message. Returns: None. Always fails the current test.