Current section
Files
Jump to
Current section
Files
src/showtime.erl
-module(showtime).
-compile([no_auto_import, nowarn_unused_vars]).
-export([main/0]).
-spec run(
gleam@option:option(list(binary())),
list(binary()),
showtime@internal@common@cli:capture()
) -> nil.
run(Module_list, Ignore_tags, Capture) ->
Test_event_handler = showtime@internal@erlang@event_handler:start(),
Test_module_handler = showtime@internal@erlang@module_handler:start(
Test_event_handler,
fun showtime@internal@erlang@discover:collect_test_functions/1,
fun showtime@internal@erlang@runner:run_test_suite/4,
Ignore_tags,
Capture
),
Test_event_handler(start_test_run),
Modules = showtime@internal@erlang@discover:collect_modules(
Test_module_handler,
Module_list
),
Test_event_handler(
{end_test_run,
begin
_pipe = Modules,
gleam@list:length(_pipe)
end}
),
nil.
-spec mk_runner(
fun((gleam@option:option(list(binary())), list(binary()), showtime@internal@common@cli:capture()) -> nil)
) -> fun((glint:command_input()) -> nil).
mk_runner(Func) ->
fun(Command) ->
Module_list@1 = case begin
_pipe = erlang:element(3, Command),
_pipe@1 = glint@flag:get(_pipe, <<"modules"/utf8>>),
gleam@result:unwrap(_pipe@1, {ls, []})
end of
{ls, Module_list} ->
case Module_list of
[] ->
none;
_ ->
{some, Module_list}
end;
_ ->
none
end,
Ignore_tags@1 = case begin
_pipe@2 = erlang:element(3, Command),
_pipe@3 = glint@flag:get(_pipe@2, <<"ignore"/utf8>>),
gleam@result:unwrap(_pipe@3, {ls, []})
end of
{ls, Ignore_tags} ->
Ignore_tags;
_ ->
[]
end,
Capture_output_result = case begin
_pipe@4 = erlang:element(3, Command),
_pipe@5 = glint@flag:get(_pipe@4, <<"capture"/utf8>>),
_pipe@6 = gleam@result:map(
_pipe@5,
fun(Arg) ->
{s, String_arg} = case Arg of
{s, _} -> Arg;
_assert_fail ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail,
module => <<"showtime"/utf8>>,
function => <<"mk_runner"/utf8>>,
line => 172})
end,
{s, gleam@string:lowercase(String_arg)}
end
),
gleam@result:unwrap(_pipe@6, {s, <<"no"/utf8>>})
end of
{s, <<"no"/utf8>>} ->
{ok, no};
{s, <<"yes"/utf8>>} ->
{ok, yes};
{s, <<"mixed"/utf8>>} ->
{ok, mixed};
_ ->
snag:error(
<<"Expected capture to be one of: ['yes', 'no', 'mixed']"/utf8>>
)
end,
case Capture_output_result of
{ok, Capture_output} ->
Func(Module_list@1, Ignore_tags@1, Capture_output);
{error, Error} ->
_pipe@7 = Error,
_pipe@8 = snag:pretty_print(_pipe@7),
gleam@io:println(_pipe@8)
end
end.
-spec start_with_args(
list(binary()),
fun((gleam@option:option(list(binary())), list(binary()), showtime@internal@common@cli:capture()) -> nil)
) -> nil.
start_with_args(Args, Func) ->
_pipe = glint:new(),
_pipe@1 = glint:add_command(
_pipe,
[],
mk_runner(Func),
[glint@flag:strings(
<<"modules"/utf8>>,
[],
<<"Run only tests in the modules in this list"/utf8>>
),
glint@flag:strings(
<<"ignore"/utf8>>,
[],
<<"Ignore tests that are have tags matching a tag in this list"/utf8>>
),
glint@flag:string(
<<"capture"/utf8>>,
<<"no"/utf8>>,
<<"Capture output: no (default) - output when tests are run, yes - output is captured and shown in report, mixed - output when run and in report"/utf8>>
)],
<<"Runs test"/utf8>>
),
glint:run(_pipe@1, Args).
-spec main() -> nil.
main() ->
start_with_args(gleam@erlang:start_arguments(), fun run/3).