Current section

Files

Jump to
startest src startest@reporter.erl
Raw

src/startest@reporter.erl

-module(startest@reporter).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([report_summary/7]).
-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 report_summary(
startest@context:context(),
list(startest@locator:test_file()),
list(startest@test_case:executed_test()),
list({startest@test_case:test(), startest@test_failure:test_failure()}),
birl@duration:duration(),
birl@duration:duration(),
birl@duration:duration()
) -> nil.
report_summary(
Ctx,
Test_files,
Tests,
Failed_tests,
Discovery_duration,
Execution_duration,
Reporting_duration
) ->
Total_test_count = gleam@list:length(Tests),
Failed_test_count = gleam@list:length(Failed_tests),
Passed_test_count = Total_test_count - Failed_test_count,
Has_any_failures = Failed_test_count > 0,
case Has_any_failures of
true ->
startest@logger:log(erlang:element(4, Ctx), <<""/utf8>>),
startest@logger:log(
erlang:element(4, Ctx),
gleam_community@ansi:black(
gleam_community@ansi:bg_bright_red(
<<<<" Failed Tests: "/utf8,
(gleam@int:to_string(Failed_test_count))/binary>>/binary,
" "/utf8>>
)
)
),
startest@logger:log(erlang:element(4, Ctx), <<""/utf8>>),
_pipe = Failed_tests,
gleam@list:each(
_pipe,
fun(Failed_test) ->
{Test_case, Failure} = Failed_test,
startest@logger:log(
erlang:element(4, Ctx),
<<<<<<<<(gleam_community@ansi:black(
gleam_community@ansi:bg_bright_red(
<<" FAIL "/utf8>>
)
))/binary,
" "/utf8>>/binary,
(erlang:element(2, Test_case))/binary>>/binary,
"\n"/utf8>>/binary,
(startest@test_failure:to_string(Failure))/binary>>
)
end
);
false ->
nil
end,
Total_duration = begin
_pipe@1 = bigben@clock:now(erlang:element(3, Ctx)),
birl:difference(_pipe@1, erlang:element(5, Ctx))
end,
Passed_tests = case Passed_test_count of
0 ->
none;
_ ->
{some,
gleam_community@ansi:bright_green(
<<(gleam@int:to_string(Passed_test_count))/binary,
" passed"/utf8>>
)}
end,
Failed_tests@1 = case Failed_test_count of
0 ->
none;
_ ->
{some,
gleam_community@ansi:bright_red(
<<(gleam@int:to_string(Failed_test_count))/binary,
" failed"/utf8>>
)}
end,
Total_tests = gleam_community@ansi:gray(
<<<<"("/utf8, (gleam@int:to_string(Total_test_count))/binary>>/binary,
")"/utf8>>
),
Failed_or_passed_tests = case {Passed_tests, Failed_tests@1} of
{{some, Passed_tests@1}, {some, Failed_tests@2}} ->
<<<<Failed_tests@2/binary, " | "/utf8>>/binary,
Passed_tests@1/binary>>;
{{some, Tests@1}, none} ->
Tests@1;
{none, {some, Tests@1}} ->
Tests@1;
{none, none} ->
<<""/utf8>>
end,
Started_at = begin
_pipe@2 = erlang:element(5, Ctx),
_pipe@4 = birl:set_offset(
_pipe@2,
begin
_pipe@3 = birl:now(),
birl:get_offset(_pipe@3)
end
),
gleam@result:unwrap(_pipe@4, erlang:element(5, Ctx))
end,
Total_collect_duration = begin
_pipe@5 = Test_files,
gleam@list:fold(
_pipe@5,
birl@duration:micro_seconds(0),
fun(Acc, Test_file) ->
birl@duration:add(Acc, erlang:element(5, Test_file))
end
)
end,
Label = fun(Text) ->
gleam_community@ansi:dim(gleam_community@ansi:white(Text))
end,
startest@logger:log(
erlang:element(4, Ctx),
<<(Label(<<"Test Files: "/utf8>>))/binary,
(gleam@int:to_string(gleam@list:length(Test_files)))/binary>>
),
startest@logger:log(
erlang:element(4, Ctx),
<<<<<<(Label(<<" Tests: "/utf8>>))/binary,
Failed_or_passed_tests/binary>>/binary,
" "/utf8>>/binary,
Total_tests/binary>>
),
startest@logger:log(
erlang:element(4, Ctx),
<<(Label(<<"Started at: "/utf8>>))/binary,
(begin
_pipe@6 = Started_at,
_pipe@7 = birl:to_naive_time_string(_pipe@6),
gleam@string:slice(
_pipe@7,
0,
gleam@string:length(<<"HH:MM:SS"/utf8>>)
)
end)/binary>>
),
startest@logger:log(
erlang:element(4, Ctx),
<<<<<<(Label(<<" Duration: "/utf8>>))/binary,
(duration_to_string(Total_duration))/binary>>/binary,
" "/utf8>>/binary,
(Label(
<<<<<<<<<<<<<<<<"(discover "/utf8,
(duration_to_string(
Discovery_duration
))/binary>>/binary,
", collect "/utf8>>/binary,
(duration_to_string(
Total_collect_duration
))/binary>>/binary,
", tests "/utf8>>/binary,
(duration_to_string(Execution_duration))/binary>>/binary,
", reporters "/utf8>>/binary,
(duration_to_string(Reporting_duration))/binary>>/binary,
")"/utf8>>
))/binary>>
).