Current section

Files

Jump to
startest src startest@test_failure.erl
Raw

src/startest@test_failure.erl

-module(startest@test_failure).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-define(FILEPATH, "src/startest/test_failure.gleam").
-export([to_string/1, rescue/1]).
-export_type([test_failure/0, panic_info/0, panic_key/0]).
-type test_failure() :: {assertion_error,
startest@assertion_error:rescued_assertion_error()} |
{generic_error, exception:exception()}.
-type panic_info() :: {panic_info, binary(), binary(), integer(), binary()}.
-type panic_key() :: module | function | message | line.
-file("src/startest/test_failure.gleam", 33).
-spec to_string(test_failure()) -> binary().
to_string(Failure) ->
case Failure of
{assertion_error, Assertion_error} ->
erlang:element(2, Assertion_error);
{generic_error, Exception} ->
gleam@string:inspect(Exception)
end.
-file("src/startest/test_failure.gleam", 51).
-spec try_decode_panic_info(exception:exception()) -> {ok, panic_info()} |
{error, nil}.
try_decode_panic_info(Exception) ->
Err@1 = case Exception of
{errored, Err} ->
Err;
{thrown, Err} ->
Err;
{exited, Err} ->
Err
end,
case gleam_stdlib:classify_dynamic(Err@1) of
<<"Dict"/utf8>> ->
gleam@result:'try'(
begin
_pipe = Err@1,
_pipe@1 = gleam@dynamic@decode:run(
_pipe,
gleam@dynamic@decode:dict(
{decoder, fun gleam@dynamic@decode:decode_dynamic/1},
{decoder, fun gleam@dynamic@decode:decode_dynamic/1}
)
),
gleam@result:replace_error(_pipe@1, nil)
end,
fun(Dict) ->
gleam@result:'try'(
begin
_pipe@2 = Dict,
_pipe@3 = gleam_stdlib:map_get(
_pipe@2,
startest@internal@unsafe:from(module)
),
gleam@result:'try'(
_pipe@3,
fun(Value) -> _pipe@4 = Value,
_pipe@5 = gleam@dynamic@decode:run(
_pipe@4,
{decoder,
fun gleam@dynamic@decode:decode_string/1}
),
gleam@result:replace_error(_pipe@5, nil) end
)
end,
fun(Module) ->
gleam@result:'try'(
begin
_pipe@6 = Dict,
_pipe@7 = gleam_stdlib:map_get(
_pipe@6,
startest@internal@unsafe:from(function)
),
gleam@result:'try'(
_pipe@7,
fun(Value@1) -> _pipe@8 = Value@1,
_pipe@9 = gleam@dynamic@decode:run(
_pipe@8,
{decoder,
fun gleam@dynamic@decode:decode_string/1}
),
gleam@result:replace_error(
_pipe@9,
nil
) end
)
end,
fun(Function) ->
gleam@result:'try'(
begin
_pipe@10 = Dict,
_pipe@11 = gleam_stdlib:map_get(
_pipe@10,
startest@internal@unsafe:from(
line
)
),
gleam@result:'try'(
_pipe@11,
fun(Value@2) ->
_pipe@12 = Value@2,
_pipe@13 = gleam@dynamic@decode:run(
_pipe@12,
{decoder,
fun gleam@dynamic@decode:decode_int/1}
),
gleam@result:replace_error(
_pipe@13,
nil
)
end
)
end,
fun(Line) ->
gleam@result:'try'(
begin
_pipe@14 = Dict,
_pipe@15 = gleam_stdlib:map_get(
_pipe@14,
startest@internal@unsafe:from(
message
)
),
gleam@result:'try'(
_pipe@15,
fun(Value@3) ->
_pipe@16 = Value@3,
_pipe@17 = gleam@dynamic@decode:run(
_pipe@16,
{decoder,
fun gleam@dynamic@decode:decode_string/1}
),
gleam@result:replace_error(
_pipe@17,
nil
)
end
)
end,
fun(Message) ->
{ok,
{panic_info,
Module,
Function,
Line,
Message}}
end
)
end
)
end
)
end
)
end
);
<<"Object"/utf8>> ->
gleam@result:'try'(
begin
_pipe@18 = Err@1,
_pipe@19 = gleam@dynamic@decode:run(
_pipe@18,
gleam@dynamic@decode:field(
<<"module"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun gleam@dynamic@decode:success/1
)
),
gleam@result:replace_error(_pipe@19, nil)
end,
fun(Module@1) ->
gleam@result:'try'(
begin
_pipe@20 = Err@1,
_pipe@21 = gleam@dynamic@decode:run(
_pipe@20,
gleam@dynamic@decode:field(
<<"fn"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun gleam@dynamic@decode:success/1
)
),
gleam@result:replace_error(_pipe@21, nil)
end,
fun(Function@1) ->
gleam@result:'try'(
begin
_pipe@22 = Err@1,
_pipe@23 = gleam@dynamic@decode:run(
_pipe@22,
gleam@dynamic@decode:field(
<<"line"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_int/1},
fun gleam@dynamic@decode:success/1
)
),
gleam@result:replace_error(_pipe@23, nil)
end,
fun(Line@1) ->
gleam@result:'try'(
begin
_pipe@24 = Err@1,
_pipe@25 = gleam@dynamic@decode:run(
_pipe@24,
gleam@dynamic@decode:field(
<<"message"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun gleam@dynamic@decode:success/1
)
),
gleam@result:replace_error(
_pipe@25,
nil
)
end,
fun(Message@1) ->
{ok,
{panic_info,
Module@1,
Function@1,
Line@1,
Message@1}}
end
)
end
)
end
)
end
);
_ ->
{error, nil}
end.
-file("src/startest/test_failure.gleam", 17).
-spec rescue(fun(() -> nil)) -> {ok, nil} | {error, test_failure()}.
rescue(F) ->
case exception_ffi:rescue(F) of
{ok, nil} ->
{ok, nil};
{error, Exception} ->
Panic_info = begin
_pipe = Exception,
try_decode_panic_info(_pipe)
end,
case Panic_info of
{ok, Panic_info@1} ->
{error,
{assertion_error,
{rescued_assertion_error,
erlang:element(5, Panic_info@1)}}};
{error, nil} ->
{error, {generic_error, Exception}}
end
end.