Current section
Files
Jump to
Current section
Files
src/metamon@annotate.erl
-module(metamon@annotate).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/metamon/annotate.gleam").
-export([annotate/1, annotate_value/2, current_annotations/0, footnote/1, reset/0, current_footnotes/0]).
-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(
" Add per-property context that is only displayed when the property\n"
" fails. Successful runs discard all annotations so the cost is zero\n"
" in the happy path.\n"
"\n"
" The runner clears state at the start of every run and reads any\n"
" remaining state on failure.\n"
).
-file("src/metamon/annotate.gleam", 62).
-spec read(binary()) -> list(binary()).
read(Key) ->
case metamon_ffi:state_get(Key) of
{error, _} ->
[];
{ok, Raw} ->
_pipe = metamon_ffi:identity(Raw),
lists:reverse(_pipe)
end.
-file("src/metamon/annotate.gleam", 56).
-spec push(binary(), binary()) -> nil.
push(Key, Message) ->
Updated = [Message | read(Key)],
metamon_ffi:state_put(Key, Updated),
nil.
-file("src/metamon/annotate.gleam", 19).
?DOC(
" Add a free-form message to the current property's annotation buffer.\n"
" Successful runs discard the buffer, so this is cheap.\n"
).
-spec annotate(binary()) -> nil.
annotate(Message) ->
push(<<"annotations"/utf8>>, Message).
-file("src/metamon/annotate.gleam", 26).
?DOC(
" Pretty-print `value` and add it to the annotation buffer with a\n"
" human-readable label. The output uses Gleam's `string.inspect` so it\n"
" works on any type.\n"
).
-spec annotate_value(binary(), any()) -> nil.
annotate_value(Label, Value) ->
Rendered = <<<<Label/binary, ": "/utf8>>/binary,
(gleam@string:inspect(Value))/binary>>,
push(<<"annotations"/utf8>>, Rendered).
-file("src/metamon/annotate.gleam", 47).
?DOC(
" Read the annotations recorded since the last `reset`. Order is the\n"
" order in which they were registered.\n"
).
-spec current_annotations() -> list(binary()).
current_annotations() ->
read(<<"annotations"/utf8>>).
-file("src/metamon/annotate.gleam", 33).
?DOC(
" Add a short message to the footnote buffer (printed at the bottom\n"
" of the failure report).\n"
).
-spec footnote(binary()) -> nil.
footnote(Message) ->
push(<<"footnotes"/utf8>>, Message).
-file("src/metamon/annotate.gleam", 39).
?DOC(
" Clear annotation and footnote buffers. Called by the runner before\n"
" each property run.\n"
).
-spec reset() -> nil.
reset() ->
metamon_ffi:state_erase(<<"annotations"/utf8>>),
metamon_ffi:state_erase(<<"footnotes"/utf8>>),
nil.
-file("src/metamon/annotate.gleam", 52).
?DOC(" Read the footnotes recorded since the last `reset`.\n").
-spec current_footnotes() -> list(binary()).
current_footnotes() ->
read(<<"footnotes"/utf8>>).