Current section
Files
Jump to
Current section
Files
src/startest@internal@runner@core.erl
-module(startest@internal@runner@core).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([run_tests/2]).
-spec run_test(startest@test_case:test()) -> startest@test_case:test_outcome().
run_test(Test_case) ->
case erlang:element(4, Test_case) of
true ->
skipped;
false ->
case startest@test_failure:rescue(erlang:element(3, Test_case)) of
{ok, nil} ->
passed;
{error, Err} ->
{failed, Err}
end
end.
-spec duration_to_string(birl@duration:duration()) -> binary().
duration_to_string(Duration) ->
Parts = birl@duration:decompose(Duration),
case Parts of
[{Microseconds, micro_second}] ->
<<(gleam@int:to_string(Microseconds))/binary, "µs"/utf8>>;
[{Milliseconds, milli_second}, {_, micro_second}] ->
<<(gleam@int:to_string(Milliseconds))/binary, "ms"/utf8>>;
[{Seconds, second}, {_, milli_second}, {_, micro_second}] ->
<<(gleam@int:to_string(Seconds))/binary, "s"/utf8>>;
[{Minutes, minute}, {_, second}, {_, milli_second}, {_, micro_second}] ->
<<(gleam@int:to_string(Minutes))/binary, "m"/utf8>>;
_ ->
<<"too long"/utf8>>
end.
-spec run_tests(
list(startest@test_tree:test_tree()),
startest@context:context()
) -> nil.
run_tests(Tests, Ctx) ->
Started_at = birl:utc_now(),
Tests@1 = begin
_pipe = Tests,
_pipe@1 = gleam@list:flat_map(
_pipe,
fun(Tree) -> startest@test_tree:all_tests(Tree) end
),
gleam@list:filter(
_pipe@1,
fun(Pair) ->
{Test_name, _} = Pair,
case erlang:element(5, erlang:element(2, Ctx)) of
{some, Test_name_pattern} ->
gleam_stdlib:contains_string(
Test_name,
Test_name_pattern
);
none ->
true
end
end
)
end,
Test_count = gleam@list:length(Tests@1),
startest@logger:log(
erlang:element(3, Ctx),
<<<<"Running "/utf8, (gleam@int:to_string(Test_count))/binary>>/binary,
" tests"/utf8>>
),
Execution_started_at = birl:utc_now(),
Executed_tests = begin
_pipe@2 = Tests@1,
gleam@list:map(
_pipe@2,
fun(Pair@1) ->
Test_case = {test,
erlang:element(1, Pair@1),
erlang:element(3, (erlang:element(2, Pair@1))),
erlang:element(4, (erlang:element(2, Pair@1)))},
{executed_test, Test_case, run_test(Test_case)}
end
)
end,
Execution_duration = begin
_pipe@3 = birl:utc_now(),
birl:difference(_pipe@3, Execution_started_at)
end,
Reporter_ctx = {reporter_context, erlang:element(3, Ctx)},
_pipe@4 = erlang:element(2, erlang:element(2, Ctx)),
gleam@list:each(
_pipe@4,
fun(Reporter) ->
_pipe@5 = Executed_tests,
gleam@list:each(
_pipe@5,
fun(Executed_test) ->
(erlang:element(2, Reporter))(Reporter_ctx, Executed_test)
end
),
(erlang:element(3, Reporter))(Reporter_ctx)
end
),
Failed_tests = begin
_pipe@6 = Executed_tests,
gleam@list:filter_map(
_pipe@6,
fun(Executed_test@1) -> case erlang:element(3, Executed_test@1) of
{failed, Failure} ->
{ok, {erlang:element(2, Executed_test@1), Failure}};
passed ->
{error, nil};
skipped ->
{error, nil}
end end
)
end,
startest@reporter:report_summary(Ctx, Failed_tests),
Total_duration = begin
_pipe@7 = birl:utc_now(),
birl:difference(_pipe@7, Started_at)
end,
startest@logger:log(
erlang:element(3, Ctx),
<<<<<<"Ran "/utf8, (gleam@int:to_string(Test_count))/binary>>/binary,
" tests in "/utf8>>/binary,
(duration_to_string(Total_duration))/binary>>
),
startest@logger:log(
erlang:element(3, Ctx),
<<"Execution time: "/utf8,
(duration_to_string(Execution_duration))/binary>>
),
Exit_code = case gleam@list:is_empty(Failed_tests) of
true ->
0;
false ->
1
end,
erlang:halt(Exit_code).