-
Notifications
You must be signed in to change notification settings - Fork 136
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
Make test suite work in OTP 25 #1402
Changes from 20 commits
69b6047
9c5d5d1
c7463bd
9c4cfb0
9b12c7c
746e727
2887d3d
de4f89d
b1bc61c
0e15306
ab98ee5
09f09b5
3dcd3e1
ae4eda0
222c07e
f1e265c
187acdb
3db8e76
13db044
2769499
ca1aa6c
27601e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,12 +78,21 @@ init_per_testcase(TestCase, Config) -> | |
|
||
-spec end_per_testcase(atom(), config()) -> ok. | ||
end_per_testcase(TestCase, Config) -> | ||
lists:foreach( | ||
fun | ||
(els_docs_meck) -> meck:unload(els_docs); | ||
(_) -> ok | ||
end, | ||
erlang:registered() | ||
), | ||
els_test_utils:end_per_testcase(TestCase, Config). | ||
|
||
%%============================================================================== | ||
%% Testcases | ||
%%============================================================================== | ||
local_call_no_args(Config) -> | ||
%% this test is for the fallback render when no doc chunks are available | ||
mock_doc_chunks_unavailable(), | ||
Uri = ?config(hover_docs_caller_uri, Config), | ||
#{result := Result} = els_client:hover(Uri, 10, 7), | ||
?assert(maps:is_key(contents, Result)), | ||
|
@@ -97,6 +106,8 @@ local_call_no_args(Config) -> | |
ok. | ||
|
||
local_call_with_args(Config) -> | ||
%% this test is for the fallback render when no doc chunks are available | ||
mock_doc_chunks_unavailable(), | ||
Uri = ?config(hover_docs_caller_uri, Config), | ||
#{result := Result} = els_client:hover(Uri, 13, 7), | ||
?assert(maps:is_key(contents, Result)), | ||
|
@@ -120,6 +131,8 @@ local_call_with_args(Config) -> | |
ok. | ||
|
||
remote_call_multiple_clauses(Config) -> | ||
%% this test is for the fallback render when no doc chunks are available | ||
mock_doc_chunks_unavailable(), | ||
Uri = ?config(hover_docs_caller_uri, Config), | ||
#{result := Result} = els_client:hover(Uri, 16, 15), | ||
?assert(maps:is_key(contents, Result)), | ||
|
@@ -226,6 +239,8 @@ remote_call_otp(Config) -> | |
ok. | ||
|
||
local_fun_expression(Config) -> | ||
%% this test is for the fallback render when no doc chunks are available | ||
mock_doc_chunks_unavailable(), | ||
Uri = ?config(hover_docs_caller_uri, Config), | ||
#{result := Result} = els_client:hover(Uri, 19, 5), | ||
?assert(maps:is_key(contents, Result)), | ||
|
@@ -249,6 +264,8 @@ local_fun_expression(Config) -> | |
ok. | ||
|
||
remote_fun_expression(Config) -> | ||
%% this test is for the fallback render when no doc chunks are available | ||
mock_doc_chunks_unavailable(), | ||
Uri = ?config(hover_docs_caller_uri, Config), | ||
#{result := Result} = els_client:hover(Uri, 20, 10), | ||
?assert(maps:is_key(contents, Result)), | ||
|
@@ -526,13 +543,15 @@ nonexisting_type(Config) -> | |
#{result := Result} = els_client:hover(Uri, 22, 15), | ||
%% The spec for `j' is shown instead of the type docs. | ||
Value = | ||
case has_eep48_edoc() of | ||
true -> | ||
case list_to_integer(erlang:system_info(otp_release)) of | ||
25 -> | ||
<< | ||
"## j/1\n\n---\n\n```erlang\n\n j(_) \n\n```\n\n" | ||
"```erlang\n-spec j(doesnt:exist()) -> ok.\n```" | ||
Comment on lines
-529
to
-533
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there is a bug in On OTP 24 locally on my machine, Anywho, I didn't want to make changes to the production code in this PR adding OTP 25 to CI, so not diving into if |
||
"```erlang\nj(_ :: doesnt:exist()) -> ok.\n```\n\n" | ||
"---\n\n\n" | ||
>>; | ||
false -> | ||
% els_eep48_docs:render returns {error, function_missing} for | ||
% OTP versions under 25 | ||
_ -> | ||
<< | ||
"## j/1\n\n---\n\n```erlang\n\n j(_) \n\n```\n\n" | ||
"```erlang\n-spec j(doesnt:exist()) -> ok.\n```" | ||
|
@@ -560,10 +579,30 @@ nonexisting_module(Config) -> | |
?assertEqual(Expected, Result), | ||
ok. | ||
|
||
%%============================================================================== | ||
%% Helpers | ||
%%============================================================================== | ||
|
||
mock_doc_chunks_unavailable() -> | ||
meck:expect( | ||
els_docs, | ||
eep48_docs, | ||
fun(_, _, _, _) -> {error, not_available} end | ||
). | ||
|
||
has_eep48_edoc() -> | ||
list_to_integer(erlang:system_info(otp_release)) >= 24. | ||
|
||
has_eep48(Module) -> | ||
case catch code:get_doc(Module) of | ||
{ok, _} -> true; | ||
_ -> false | ||
{ok, {docs_v1, _, erlang, _, _, _, Docs}} -> | ||
lists:any( | ||
fun | ||
({_, _, _, Doc, _}) when is_map(Doc) -> true; | ||
({_, _, _, _, _}) -> false | ||
end, | ||
Docs | ||
); | ||
_ -> | ||
false | ||
end. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fact that meck registers a module with the
_meck
suffix is an implementation detail that we should not rely on. We should only unloadels_docs
for those testcases where the module is mocked.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The correct way to do "unmock if mocked" is to use the
meck
API instead.meck:mocked
returns a list of mocked modules.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah nice to know 👍