Std.Test
View source →Test assertion primitives plus a shrinking-aware property runner.
Assertions raise an Erlang error with a descriptive atom on
failure (:assertion_failed, :not_equal, etc.). The
property-based helpers pair with Std.Gen generators.
Examples
mod MyTest
use Std.Test
fn test_sanity() -> Unit =
assert_eq(1 + 1, 2)
# Property: reversing a list twice is the identity.
use Std.Test
use Std.Gen
use Std.List
let prop = fn(xs: List(Int)) -> Bool =
reverse(reverse(xs)) == xs
forall_default(fn(_) -> list_int(10, 0, 100), prop)
# => :ok
Group tag consumed by Cure.Stdlib.Preload.
Functions
-
# fn assert(condition: Bool) -> Unit
Assert
conditionistrue; raises:assertion_failedon false. -
# fn assert_eq(a: t, b: t) -> Unit
Assert structural equality; raises
:not_equalon mismatch. Assertions are intentionally available for every runtime value, including generic containers whose element dictionary is not otherwise in lexical scope. -
# fn assert_gt(a: t, b: t) -> Unit
Assert
a > b; raises:not_greaterotherwise. -
# fn assert_lt(a: t, b: t) -> Unit
Assert
a < b; raises:not_lessotherwise. -
# fn assert_ne(a: t, b: t) -> Unit
Assert
a != b; raises:unexpectedly_equalwhen they match. -
# fn forall(gen: Function(Unit, t), property: Function(t, Bool), runs: Int) -> Unit
Run
propertyagainstrunsrandom samples drawn fromgen. Returns:okwhen every sample satisfies the property, or raises:property_failedon the first counterexample.genis a zero-argument function (e.g.fn(_) -> Std.Gen.int_in(0, 100)) that returns a fresh value on every call. -
# fn forall_default(gen: Function(Unit, t), property: Function(t, Bool)) -> Unit
Convenience wrapper that uses 100 runs by default.
-
# fn forall_shrunk(gen: Function(Unit, t), property: Function(t, Bool), runs: Int) -> Result(Unit, t) extern
Run
propertyagainstrunsrandom samples. On the first failure, shrink the counterexample until no smaller value also fails.Returns
Ok(:ok)when every sample satisfied the property, andError(minimal)carrying the minimised counterexample otherwise. Unlikeforall/3, a failing property is a value, not a raise — including a property that itself throws (treated as a failure). Given a total generator and property this never raises; a generator that throws has no witness value to return and is a caller error. -
# fn forall_shrunk_default(gen: Function(Unit, t), property: Function(t, Bool)) -> Result(Unit, t)
Same as
forall_shrunk/3but with a 100-run default.