Current section

Files

Jump to
glacier src gleeunit.erl
Raw

src/gleeunit.erl

-module(gleeunit).
-compile(no_auto_import).
-export([main/0, run/1]).
-export_type([atom_/0, encoding/0, report_module_name/0, gleeunit_progress_option/0, eunit_option/0]).
-type atom_() :: any().
-type encoding() :: utf8.
-type report_module_name() :: gleeunit_progress.
-type gleeunit_progress_option() :: {colored, boolean()}.
-type eunit_option() :: verbose |
no_tty |
{report, {report_module_name(), list(gleeunit_progress_option())}}.
-spec main() -> nil.
main() ->
_pipe = detect_all_test_modules(),
run_suite(_pipe, true).
-spec run(list(binary())) -> nil.
run(Test_module_files) ->
_pipe = Test_module_files,
_pipe@1 = find_matching_test_module_files(_pipe),
run_suite(_pipe@1, false).
-spec find_matching_test_module_files(list(binary())) -> list(binary()).
find_matching_test_module_files(Test_module_files) ->
_pipe = Test_module_files,
gleam@list:filter(
_pipe,
fun(Module_name) ->
Absolute_module_file_name = <<<<(get_cwd())/binary, "/"/utf8>>/binary,
Module_name/binary>>,
_pipe@1 = file_exists(Absolute_module_file_name),
gleam@function:tap(_pipe@1, fun(Exists) -> case Exists of
true ->
nil;
false ->
gleam@io:println(
<<"Error: Could not find "/utf8,
Absolute_module_file_name/binary>>
)
end end)
end
).
-spec detect_all_test_modules() -> list(binary()).
detect_all_test_modules() ->
do_detect_all_test_modules().
-spec get_cwd() -> binary().
get_cwd() ->
glacier_ffi:get_cwd_as_binary().
-spec file_exists(binary()) -> boolean().
file_exists(Absolute_file_name) ->
filelib:is_regular(Absolute_file_name).
-spec run_suite(list(binary()), boolean()) -> nil.
run_suite(Test_module_files, Halts_on_error) ->
do_run_suite(Test_module_files, Halts_on_error).
-spec do_run_suite(list(binary()), boolean()) -> nil.
do_run_suite(Test_module_files, Halts_on_error) ->
Options = [verbose,
no_tty,
{report, {gleeunit_progress, [{colored, true}]}}],
Result = begin
_pipe = Test_module_files,
_pipe@1 = gleam@list:map(
_pipe,
fun(Test_module_file) ->
{ok, {_@2, Test_module_file@2}} = case gleam@string:split_once(
Test_module_file,
<<"test/"/utf8>>
) of
{ok, {_@1, Test_module_file@1}} -> {ok,
{_@1, Test_module_file@1}};
_try ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _try,
module => <<"gleeunit"/utf8>>,
function => <<"do_run_suite"/utf8>>,
line => 78})
end,
Test_module_file@2
end
),
_pipe@2 = gleam@list:map(_pipe@1, fun gleam_to_erlang_module_name/1),
_pipe@3 = gleam@list:map(
_pipe@2,
fun(_capture) -> erlang:binary_to_atom(_capture, utf8) end
),
_pipe@4 = eunit:test(_pipe@3, Options),
_pipe@5 = (gleam@dynamic:result(
fun gleam@dynamic:dynamic/1,
fun gleam@dynamic:dynamic/1
))(_pipe@4),
gleam@result:unwrap(_pipe@5, {error, gleam@dynamic:from(nil)})
end,
Exit_code = case Result of
{ok, _@3} ->
0;
{error, _@4} ->
1
end,
case {Halts_on_error, Exit_code} of
{true, Exit_code@1} ->
erlang:halt(Exit_code@1);
{false, 0} ->
nil;
{false, 1} ->
nil;
{false, Unhandled_exit_code} ->
_pipe@6 = <<"Unexpected Error Code: "/utf8,
(gleam@int:to_string(Unhandled_exit_code))/binary>>,
gleam@io:println(_pipe@6),
nil
end.
-spec gleam_to_erlang_module_name(binary()) -> binary().
gleam_to_erlang_module_name(Path) ->
_pipe = Path,
_pipe@1 = gleam@string:replace(_pipe, <<".gleam"/utf8>>, <<""/utf8>>),
_pipe@2 = gleam@string:replace(_pipe@1, <<".erl"/utf8>>, <<""/utf8>>),
gleam@string:replace(_pipe@2, <<"/"/utf8>>, <<"@"/utf8>>).
-spec do_detect_all_test_modules() -> list(binary()).
do_detect_all_test_modules() ->
_pipe = gleeunit_ffi:find_files(
<<"**/*.{erl,gleam}"/utf8>>,
<<"test"/utf8>>
),
gleam@list:map(
_pipe,
fun(Test_module_file_name) ->
<<"test/"/utf8, Test_module_file_name/binary>>
end
).