Skip to content

Commit

Permalink
Start gradualizer app in each test of gradualizer_tests.erl
Browse files Browse the repository at this point in the history
Co-authored-by: Radek Szymczyszyn <[email protected]>
  • Loading branch information
xxdavid and erszcz committed Mar 5, 2023
1 parent db81bdc commit 676fde2
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions test/gradualizer_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,29 @@
-define(passing, "test/should_pass/any.erl").
-define(failing, "test/should_fail/arg.erl").

type_check_erl_file_test_() ->
global_test_() ->
{setup,
fun setup_app/0,
fun cleanup_app/1,
[{generator, fun type_check_erl_file/0},
{generator, fun type_check_erl_files/0},
{generator, fun type_check_forms/0},
{generator, fun type_check_beam_file/0},
{generator, fun type_check_module/0},
{generator, fun type_check_dir/0},
{generator, fun not_found/0},
{generator, fun bad_content/0},
{generator, fun beam_without_forms/0}
]}.

type_check_erl_file() ->
[?_assertEqual(ok, gradualizer:type_check_file(?passing)),
?_assertEqual([], gradualizer:type_check_file(?passing, [return_errors])),
?_assertEqual(nok, gradualizer:type_check_file(?failing)),
?_assertMatch([_|_], gradualizer:type_check_file(?failing, [return_errors]))
].

type_check_erl_files_test_() ->
type_check_erl_files() ->
[
?_assertEqual(ok, gradualizer:type_check_files([?passing, ?passing])),
?_assertEqual(nok, gradualizer:type_check_files([?failing, ?failing])),
Expand All @@ -24,7 +39,7 @@ type_check_erl_files_test_() ->
?_assertEqual([], gradualizer:type_check_files([?passing, ?passing], [return_errors]))
].

type_check_forms_test_() ->
type_check_forms() ->
{ok, PassingForms} = epp:parse_file(?passing, []),
%% Drop the file attribute to check that type_check_forms works without it
[{attribute, _, file, _} | PassingFormsNoFile] = PassingForms,
Expand All @@ -33,19 +48,19 @@ type_check_forms_test_() ->
?_assertEqual(ok, gradualizer:type_check_forms(PassingFormsNoFile, []))
].

type_check_beam_file_test() ->
type_check_beam_file() ->
Dir = filename:dirname(?FILE), % this differs when /not/ using rebar
BeamFile = filename:join(Dir, "any.beam"),
?_assertEqual(ok, gradualizer:type_check_file(BeamFile)).

type_check_module_test() ->
type_check_module() ->
{module, Mod} = code:load_file(any),
?assertEqual(ok, gradualizer:type_check_module(Mod)).
?_assertEqual(ok, gradualizer:type_check_module(Mod)).

type_check_dir_test() ->
?assertEqual(nok, gradualizer:type_check_dir("test/dir/")).
type_check_dir() ->
?_assertEqual(nok, gradualizer:type_check_dir("test/dir/")).

not_found_test_() ->
not_found() ->
[
?_assertThrow({file_not_found, "test/not_found.erl"},
gradualizer:type_check_file("test/not_found.erl")),
Expand All @@ -61,14 +76,14 @@ not_found_test_() ->
gradualizer:type_check_module(erlang))
].

bad_content_test_() ->
bad_content() ->
{setup,
fun() -> file:write_file("test/bad_content.beam", "bad content") end,
fun(_) -> file:delete("test/bad_content.beam") end,
?_assertThrow({forms_error,{not_a_beam_file, 'test/bad_content.beam'}},
gradualizer:type_check_file("test/bad_content.beam"))}.

beam_without_forms_test_() ->
beam_without_forms() ->
{setup,
fun() ->
{ok, any} = compile:file("test/should_pass/any.erl",
Expand All @@ -77,3 +92,12 @@ beam_without_forms_test_() ->
fun(_) -> file:delete("test/should_pass/any.beam") end,
?_assertThrow({forms_not_found, "test/should_pass/any.beam"},
gradualizer:type_check_file("test/should_pass/any.beam"))}.


setup_app() ->
{ok, Apps} = application:ensure_all_started(gradualizer),
Apps.

cleanup_app(Apps) ->
[ok = application:stop(App) || App <- Apps],
ok.

0 comments on commit 676fde2

Please sign in to comment.