Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow timeouts in tests #535

Merged
merged 2 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions test/known_problems/should_fail/recursive_types_should_fail.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-module(recursive_types_should_fail).

-export([recursive_param1/1,
recursive_param3/1]).

-type rec1(A) :: A | rec1({A | rec1(A)}).

-spec recursive_param1(rec1(integer())) -> ok.
recursive_param1({qwe, zxc}) -> ok.

-type rec3(A) :: A | rec3(A).

%% `ok' is not an `integer()' - this should fail.
-spec recursive_param3(rec3(integer())) -> atom().
recursive_param3(ok) -> ok.
19 changes: 2 additions & 17 deletions test/should_fail/recursive_types_failing.erl
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
-module(recursive_types_failing).

-export([recursive_param1/1,
recursive_param2/1,
recursive_param3/1]).

-type rec1(A) :: A | rec1({A | rec1(A)}).

-spec recursive_param1(rec1(integer())) -> ok.
recursive_param1({qwe, zxc}) -> ok.

-export([recursive_param2/1]).

-type rec2() :: rec2 | {rec2, rec2()} | {rec2, {rec2, rec2()}}.

%% `{_, Z}' doesn't match on atom `rec2', which is a valid value of type `rec2()'.
%% This should fail.
-spec recursive_param2(rec2()) -> rec2().
recursive_param2({_, Z}) -> Z.


-type rec3(A) :: A | rec3(A).

%% `ok' is not an `integer()' - this should fail.
-spec recursive_param3(rec3(integer())) -> atom().
recursive_param3(ok) -> ok.
recursive_param2({_, Z}) -> Z.
15 changes: 13 additions & 2 deletions test/test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ gen_should_fail() ->
fun(File) ->
fun() ->
Errors = gradualizer:type_check_file(File, [return_errors]),
Timeouts = [ E || {_File, {form_check_timeout, _}} = E <- Errors],
?assertEqual(0, length(Timeouts)),
%% Test that error formatting doesn't crash
Opts = [{fmt_location, brief},
{fmt_expr_fun, fun erl_prettypr:format/1}],
Expand All @@ -63,12 +65,21 @@ gen_known_problem_should_pass() ->
?_assertEqual(ExpectedErrors, ReturnedErrors)
end, "test/known_problems/should_pass").

% Test succeeds if Gradualizer crashes or if it does type check.
% Test succeeds if Gradualizer crashes, times out, or if it does type check.
% Doing so makes the test suite notify us whenever a known problem is resolved.
gen_known_problem_should_fail() ->
map_erl_files(
fun(File) ->
?_assertNotEqual(nok, safe_type_check_file(File))
Result = safe_type_check_file(File, [return_errors]),
case Result of
crash ->
ok;
Errors ->
ErrorsExceptTimeouts = lists:filter(
fun ({_File, {form_check_timeout, _}}) -> false; (_) -> true end,
Errors),
?_assertEqual(0, length(ErrorsExceptTimeouts))
end
end, "test/known_problems/should_fail").

%%
Expand Down