Skip to main content

Test

The Aleph Test module provides expectations, matchers, and tolerance constants used by native Aleph tests.

Test declarations can live next to production functions and classes. When a file is run in test mode, root executable statements and root value initialization are not executed; functions, classes, test declarations, and include declarations are collected so selected tests can run in isolated test contexts. Expectations are active in test bodies, before_each hooks, and after_each hooks; before_all and after_all are setup/teardown hooks only.

Examples


def add(lhs, rhs) {
lhs + rhs
}

test_section "Math" {
var calls = 0

before_all {
println("starting math tests")
}

before_each {
calls += 1
}

test "adds numbers" {
expect(add(2, 3)).to_equal(5)
expect(calls).to_be_greater_than(0)
}

test "squares values"(value, expected)
cases [[2, 4], [3, 9]]
options ["timeout": 1000, "abs_tolerance": 1e-12] {
expect(value * value).to_equal(expected)
}

after_each {
expect(calls).to_be_greater_than(0)
}

after_all {
println("finished math tests")
}
}

Global Constants

NameDescription
default_abs_toleranceDefault absolute tolerance used by non-strict numeric equality matchers.
default_rel_toleranceDefault relative tolerance used by non-strict numeric equality matchers.

Types

NameDescription
AlephExpectationRepresents an expectation created by expect inside an active Aleph test.

Module Functions

NameDescription
expectCreates an expectation for use inside Aleph tests.