package hegel

  1. Overview
  2. Docs

Module Stateful.InvariantSource

Sourcetype 'state t

An invariant is a property that must always be true in a stateful test.

Sourceval create : name:string -> inv:(test_case -> 'state -> unit) -> ?always_check:bool -> unit -> 'state t

Declares an invariant.

  • name is printed in the final output if the test fails on an invariant
  • inv tc state checks the invariant on state. Anything it draws or notes through tc prints indented under the line before it.
  • always_check defaults to false. When true, the invariant is checked after every step. Otherwise, it is sampled.

Every invariant is checked on the initial and final states.

let short =
  Stateful.Invariant.create
    ~name:"short"
    ~inv:(fun _tc stack -> assert (List.length stack < 10))
    ()
;;
Sourceval name : _ t -> string

Returns the name of the invariant.