-module(gleeunit). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([main/0, run/2]). -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 find_matching_test_module_files(list(binary())) -> list(binary()). find_matching_test_module_files(Test_module_files) -> _pipe = Test_module_files, _pipe@2 = gleam@list:filter( _pipe, fun(Module_name) -> begin _pipe@1 = Module_name, gleam@string:ends_with(_pipe@1, <<".gleam"/utf8>>) end =:= true end ), gleam@list:filter( _pipe@2, fun(Module_name@1) -> Absolute_module_file_name = <<<<(gleeunit_ffi:get_cwd_as_binary())/binary, "/"/utf8>>/binary, Module_name@1/binary>>, _pipe@3 = filelib:is_regular(Absolute_module_file_name), gleam@function:tap(_pipe@3, fun(Exists) -> case Exists of true -> nil; false -> gleam@io:println_error( <<"Error: Could not find "/utf8, Absolute_module_file_name/binary>> ) end end) 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 detect_all_test_modules() -> list(binary()). 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 ). -spec run_suite(list(binary()), boolean()) -> nil. 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) -> _assert_subject = gleam@string:split_once( Test_module_file, <<"test/"/utf8>> ), {ok, {_, Test_module_file@1}} = case _assert_subject of {ok, {_, _}} -> _assert_subject; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Assertion pattern match failed"/utf8>>, value => _assert_fail, module => <<"gleeunit"/utf8>>, function => <<"run_suite"/utf8>>, line => 47}) end, Test_module_file@1 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, _} -> 0; {error, _} -> 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_error(_pipe@6), nil end. -spec main() -> nil. main() -> _pipe = detect_all_test_modules(), run_suite(_pipe, true). -spec run(list(binary()), boolean()) -> nil. run(Test_module_files, Halts_on_error) -> _pipe = Test_module_files, _pipe@1 = find_matching_test_module_files(_pipe), run_suite(_pipe@1, Halts_on_error).