metamon/command

Stateful / model-based testing primitives.

A Command(model, real) represents one transition that can be applied to two parallel worlds:

The precondition decides whether the command can fire in the current model state; the runner skips commands whose preconditions are false.

See metamon/stateful for the runner that drives a list of commands against an initial (model, real) pair.

Types

A single transition in a model-based test.

pub type Command(model, real) {
  Command(
    name: String,
    precondition: fn(model) -> Bool,
    next_model: fn(model) -> model,
    run: fn(real) -> Result(Nil, String),
  )
}

Constructors

  • Command(
      name: String,
      precondition: fn(model) -> Bool,
      next_model: fn(model) -> model,
      run: fn(real) -> Result(Nil, String),
    )

Values

pub fn always(
  name name: String,
  next_model next: fn(model) -> model,
  run run: fn(real) -> Result(Nil, String),
) -> Command(model, real)

A command that always passes its precondition.

pub fn name_of(cmd: Command(model, real)) -> String

Get the command’s user-facing name.

pub fn new(
  name name: String,
  precondition pre: fn(model) -> Bool,
  next_model next: fn(model) -> model,
  run run: fn(real) -> Result(Nil, String),
) -> Command(model, real)

Construct a command. name is shown in failure reports.

Search Document