Current section
Files
Jump to
Current section
Files
src/testbldr.erl
-module(testbldr).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function]).
-export([describe/2, named/2, demonstrate/2]).
-spec describe(binary(), fun(() -> list(testbldr@pieces:test()))) -> {binary(),
list(testbldr@pieces:test())}.
describe(Name, Fun) ->
{Name, Fun()}.
-spec named(binary(), fun(() -> testbldr@pieces:test_outcome())) -> testbldr@pieces:test().
named(Name, New_test) ->
{test, Name, New_test}.
-spec demonstrate(list(testbldr@pieces:test()), binary()) -> nil.
demonstrate(Input, Name) ->
gleam@io:println(
<<<<"\nDemonstrating that: "/utf8, Name/binary>>/binary, "\n"/utf8>>
),
Total_tests = gleam@list:length(Input),
Total_passed = begin
_pipe = Input,
gleam@list:index_fold(
_pipe,
0,
fun(Acc, Test, Index) ->
{test, Name@1, Test_function} = Test,
case gleam_erlang_ffi:rescue(Test_function) of
{ok, pass} ->
gleam@io:print(
<<(gleam@int:to_string(Index + 1))/binary,
". "/utf8>>
),
_pipe@1 = (<<<<"Test \""/utf8, Name@1/binary>>/binary,
"\" passed"/utf8>>),
_pipe@2 = gleam_community@ansi:green(_pipe@1),
gleam@io:println(_pipe@2),
Acc + 1;
{ok, {fail, Msg}} ->
gleam@io:print(
<<(gleam@int:to_string(Index + 1))/binary,
". "/utf8>>
),
_pipe@3 = (<<<<"Test \""/utf8, Name@1/binary>>/binary,
"\" failed: "/utf8>>),
_pipe@4 = gleam_community@ansi:red(_pipe@3),
gleam@io:println(_pipe@4),
_pipe@5 = Msg,
gleam@io:println(_pipe@5),
Acc;
{error, _} ->
gleam@io:print(
<<(gleam@int:to_string(Index + 1))/binary,
". "/utf8>>
),
_pipe@6 = (<<<<"Test \""/utf8, Name@1/binary>>/binary,
"\" panicked!"/utf8>>),
_pipe@7 = gleam_community@ansi:red(_pipe@6),
gleam@io:println(_pipe@7),
Acc
end
end
)
end,
Ratio = <<<<<<<<"\n"/utf8, (gleam@int:to_string(Total_passed))/binary>>/binary,
"/"/utf8>>/binary,
(gleam@int:to_string(Total_tests))/binary>>/binary,
" tests passed\n"/utf8>>,
case Total_passed =:= Total_tests of
true ->
_pipe@8 = Ratio,
_pipe@9 = gleam_community@ansi:green(_pipe@8),
gleam@io:println(_pipe@9);
false ->
_pipe@10 = Ratio,
_pipe@11 = gleam_community@ansi:red(_pipe@10),
gleam@io:println(_pipe@11)
end.