-module(testbldr). -compile([no_auto_import, nowarn_unused_vars]). -export([pass/0, fail/1, test/3, tests/2, run/1]). -export_type([test_outcome/0]). -type test_outcome() :: pass | {fail, binary()}. -spec pass() -> test_outcome(). pass() -> pass. -spec fail(binary()) -> test_outcome(). fail(Msg) -> {fail, Msg}. -spec test( list({binary(), fun(() -> test_outcome())}), binary(), fun(() -> test_outcome()) ) -> list({binary(), fun(() -> test_outcome())}). test(Input, Name, New_test) -> [{Name, New_test} | Input]. -spec tests( list({binary(), fun(() -> test_outcome())}), list({binary(), fun(() -> test_outcome())}) ) -> list({binary(), fun(() -> test_outcome())}). tests(Input, New_tests) -> gleam@list:append(Input, New_tests). -spec run(list({binary(), fun(() -> test_outcome())})) -> nil. run(Input) -> gleam@io:println(<<"Running tests...\n\n"/utf8>>), Total_tests = gleam@list:length(Input), Total_passed = begin _pipe = Input, _pipe@1 = gleam@list:map( _pipe, fun(Test) -> {Name, Test@1} = Test, {Name, gleam@otp@task:async(Test@1)} end ), gleam@list:index_fold( _pipe@1, 0, fun(Acc, Test@2, Index) -> {Name@1, Test@3} = Test@2, case gleam@otp@task:try_await_forever(Test@3) of {ok, pass} -> gleam@io:print( <<(gleam@int:to_string(Index + 1))/binary, ". "/utf8>> ), _pipe@2 = (<>), _pipe@3 = colours:fggreen1(_pipe@2), gleam@io:println(_pipe@3), Acc + 1; {ok, {fail, Msg}} -> gleam@io:print( <<(gleam@int:to_string(Index + 1))/binary, ". "/utf8>> ), _pipe@4 = (<<<>/binary, Msg/binary>>), _pipe@5 = colours:fgred1(_pipe@4), gleam@io:println(_pipe@5), Acc; {error, _} -> gleam@io:print( <<(gleam@int:to_string(Index + 1))/binary, ". "/utf8>> ), _pipe@6 = (<>), _pipe@7 = colours:fgred1(_pipe@6), gleam@io:println(_pipe@7), Acc end end ) end, Ratio = <<<<<<<<"\n\n"/utf8, (gleam@int:to_string(Total_passed))/binary>>/binary, "/"/utf8>>/binary, (gleam@int:to_string(Total_tests))/binary>>/binary, " tests passed"/utf8>>, case Total_passed =:= Total_tests of true -> _pipe@8 = Ratio, _pipe@9 = colours:fggreen1(_pipe@8), gleam@io:println(_pipe@9); false -> _pipe@10 = Ratio, _pipe@11 = colours:fgred1(_pipe@10), gleam@io:println(_pipe@11) end.