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() -> Atom =
    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

Functions

  • # fn __group__() -> Atom

    Group tag consumed by Cure.Stdlib.Preload.

  • # fn assert(condition: Bool) -> Atom

    Assert condition is true; raises :assertion_failed on false.

  • # fn assert_eq(a: T, b: T) -> Atom

    Assert a == b; raises :not_equal on mismatch.

  • # fn assert_gt(a: T, b: T) -> Atom

    Assert a > b; raises :not_greater otherwise.

  • # fn assert_lt(a: T, b: T) -> Atom

    Assert a < b; raises :not_less otherwise.

  • # fn assert_ne(a: T, b: T) -> Atom

    Assert a != b; raises :unexpectedly_equal when they match.

  • # fn forall(gen: (Atom) -> T, property: (T) -> Bool, runs: Int) -> Atom

    Run property against runs random samples drawn from gen. Returns :ok when every sample satisfies the property, or raises :property_failed on the first counterexample.

    gen is 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: (Atom) -> T, property: (T) -> Bool) -> Atom

    Convenience wrapper that uses 100 runs by default.

  • # fn forall_shrunk(gen: (Atom) -> T, property: (T) -> Bool, runs: Int) -> T extern

    Run property against runs random samples. On the first failure, shrink the counterexample using Std.Gen.shrink/1 until no smaller value also fails; raise :property_failed_with_shrunk carrying the minimised value.

  • # fn forall_shrunk_default(gen: (Atom) -> T, property: (T) -> Bool) -> T

    Same as forall_shrunk/3 but with a 100-run default.