Skip to content

tester

The tester package registers and runs unit tests. Testing walks through it with examples; this page is the package reference.

@tester::test("addition works")
fn test_addition()
tester::assert_eq(1 + 1, 2, "basic addition")
end
results = tester::run_tests()
println results[0]["result"] # true
FunctionDoes
@tester::test(name)Registers the decorated function as a test.
register_test(name, lambda)Registers a test without a decorator.
assert(condition, message)Fails the test if condition is false.
assert_eq(actual, expected, message)Fails the test if the values differ.
run_tests()Runs every registered test, prints a line for each, and returns a list of {name, result, duration} hashmaps.
run_test(name, lambda, results)Runs one test and appends its result.
registered(name)Whether a test with that name exists.
tester::assert_eq(actual: any, expected: any, msg: string = "")

Asserts that two values are equal, throwing on mismatch.

ParameterTypeDefaultDescription
actualanyThe value produced by the code under test.
expectedanyThe expected value.
msgstring""An optional message to include on failure.

Throws string — A failure message if actual != expected.

tester::assert(condition: boolean, msg: string = "assertion failed")

Asserts that a condition is true, throwing on failure.

ParameterTypeDefaultDescription
conditionbooleanThe condition to check.
msgstring"assertion failed"The failure message (default "assertion failed").

Throws string — A failure message if condition is false.

tester::register_test(name: string, t: lambda)

Registers a named test lambda for later execution by run_tests().

ParameterTypeDefaultDescription
namestringThe display name of the test.
tlambdaA no-argument lambda containing the test body.
tester::registered(name: string): boolean

Returns true if a test with the given name has been registered.

ParameterTypeDefaultDescription
namestringThe test name to look up.

Returns boolean — true if the test is registered.

tester::test(f: lambda, name: string): lambda

Decorator that registers a function as a named unit test.

ParameterTypeDefaultDescription
flambdaThe test function (injected by the decorator machinery).
namestringThe display name shown in the test runner output.

Returns lambda — The original function, unchanged.

@tester::test("addition works")
fn test_addition()
tester::assert(1 + 1 == 2, "basic addition")
end
tester::run_test(name: string, test: lambda, results: list = [])

Runs a single named test and prints the result.

ParameterTypeDefaultDescription
namestringThe display name of the test.
testlambdaThe test lambda to execute.
resultslist[]A list to append the result hashmap to.
tester::run_tests()

Runs all registered tests and returns a summary list.

Returns list — A list of result hashmaps, each with name, result, and duration keys.