Packages

Native desktop GUI framework for Gleam, powered by Iced

Current section

Files

Jump to
plushie_gleam src plushie@script.erl
Raw

src/plushie@script.erl

-module(plushie@script).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/plushie/script.gleam").
-export([run/2]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Run .plushie test scripts.\n"
"\n"
" Discovers .plushie script files, parses them, and executes them\n"
" against the mock backend. Reports pass/fail results.\n"
"\n"
" ```gleam\n"
" import plushie/script\n"
"\n"
" pub fn main() {\n"
" script.run([\"test/scripts\"], my_app.app())\n"
" }\n"
" ```\n"
).
-file("src/plushie/script.gleam", 60).
-spec run_script(binary(), plushie@app:app(any(), plushie@event:event())) -> {ok,
nil} |
{error, nil}.
run_script(Path, App) ->
gleam_stdlib:println(
<<<<"Running "/utf8, Path/binary>>/binary, "..."/utf8>>
),
case plushie@testing@script:parse_file(Path) of
{error, Reason} ->
gleam_stdlib:println(
<<<<" FAIL (parse error: "/utf8, Reason/binary>>/binary,
")"/utf8>>
),
{error, nil};
{ok, Script_val} ->
Sess = plushie@testing@session:start(App),
case plushie@testing@script@runner:run(Script_val, Sess) of
{ok, nil} ->
gleam_stdlib:println(<<" PASS"/utf8>>),
{ok, nil};
{error, Failures} ->
gleam@list:each(
Failures,
fun(F) ->
gleam_stdlib:println(
<<" FAIL: "/utf8,
(erlang:element(3, F))/binary>>
)
end
),
{error, nil}
end
end.
-file("src/plushie/script.gleam", 83).
-spec discover_scripts(binary()) -> list(binary()).
discover_scripts(_) ->
[].
-file("src/plushie/script.gleam", 28).
?DOC(
" Run .plushie test scripts from the given paths.\n"
"\n"
" If paths is empty, searches for .plushie files under test/scripts/.\n"
" Parses each file and executes it against a fresh test session.\n"
" Prints pass/fail results and exits with status 1 on any failure.\n"
).
-spec run(list(binary()), plushie@app:app(any(), plushie@event:event())) -> nil.
run(Paths, App) ->
Script_paths = case Paths of
[] ->
discover_scripts(<<"test/scripts"/utf8>>);
Given ->
Given
end,
case Script_paths of
[] ->
gleam_stdlib:println(<<"No .plushie scripts found"/utf8>>),
nil;
_ ->
Results = gleam@list:map(
Script_paths,
fun(_capture) -> run_script(_capture, App) end
),
Failures = gleam@list:count(
Results,
fun(R) -> R =:= {error, nil} end
),
Passes = gleam@list:count(
Results,
fun(R@1) -> R@1 =:= {ok, nil} end
),
gleam_stdlib:println(<<""/utf8>>),
gleam_stdlib:println(
<<<<<<(erlang:integer_to_binary(Passes))/binary,
" passed, "/utf8>>/binary,
(erlang:integer_to_binary(Failures))/binary>>/binary,
" failed"/utf8>>
),
case Failures > 0 of
true ->
erlang:halt(1);
false ->
nil
end
end.