Current section
Files
Jump to
Current section
Files
src/metamon@command.erl
-module(metamon@command).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/metamon/command.gleam").
-export([new/4, always/3, name_of/1]).
-export_type([command/2]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Stateful / model-based testing primitives.\n"
"\n"
" A `Command(model, real)` represents one transition that can be\n"
" applied to two parallel worlds:\n"
"\n"
" * **model**: a pure description of the expected state (typically\n"
" a record or a `Dict`). The `next_model` step says how the\n"
" command updates this expected state.\n"
" * **real**: the system under test (a database connection, a\n"
" stateful module, an in-memory cache). The `run` step performs\n"
" the command on the real world and returns `Ok(Nil)` on\n"
" success or `Error(reason)` when an invariant is violated.\n"
"\n"
" The `precondition` decides whether the command can fire in the\n"
" current model state; the runner skips commands whose preconditions\n"
" are false.\n"
"\n"
" See `metamon/stateful` for the runner that drives a list of\n"
" commands against an initial `(model, real)` pair.\n"
).
-type command(HJK, HJL) :: {command,
binary(),
fun((HJK) -> boolean()),
fun((HJK) -> HJK),
fun((HJL) -> {ok, nil} | {error, binary()})}.
-file("src/metamon/command.gleam", 32).
?DOC(" Construct a command. `name` is shown in failure reports.\n").
-spec new(
binary(),
fun((HJM) -> boolean()),
fun((HJM) -> HJM),
fun((HJN) -> {ok, nil} | {error, binary()})
) -> command(HJM, HJN).
new(Name, Pre, Next, Run) ->
{command, Name, Pre, Next, Run}.
-file("src/metamon/command.gleam", 42).
?DOC(" A command that always passes its precondition.\n").
-spec always(
binary(),
fun((HJS) -> HJS),
fun((HJT) -> {ok, nil} | {error, binary()})
) -> command(HJS, HJT).
always(Name, Next, Run) ->
{command, Name, fun(_) -> true end, Next, Run}.
-file("src/metamon/command.gleam", 51).
?DOC(" Get the command's user-facing name.\n").
-spec name_of(command(any(), any())) -> binary().
name_of(Cmd) ->
erlang:element(2, Cmd).