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

kernel: Fix code:get_doc/1,2 when cover_compiled #9433

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

williamthome
Copy link
Contributor

This PR fixes a bug getting docs when a module is compiled by the cover module. Also, the cover_compiled error was missing in the spec.

To reproduce, first compile the module via cover:compile and run code:get_doc.

Find this bug via the new doctest, for example:

% src/otp_doctest
-module(otp_doctest).

-export([foo/0]).

-doc ~"""
```
> otp_doctest:foo().
bar % must fail
```
""".
foo() ->
    foo.
% rebar.config
{profiles, [
    {test, [
        {cover_enabled, true}
    ]}
]}.
% test/otp_doctest_SUITE.erl
-module(otp_doctest_SUITE).
-behaviour(ct_suite).
-compile([export_all, nowarn_export_all]).

all() ->
    [doctests].

doctests(Config) when is_list(Config) ->
    shell_docs:test(otp_doctest, []).

The expected result is to fail, but the test passed:

$ rebar3 ct
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling otp_doctest
===> Running Common Test suites...
%%% otp_doctest_SUITE: .
All 1 tests passed.

After this PR the error is raised:

===> Verifying dependencies...
===> Analyzing applications...
===> Compiling otp_doctest
===> Running Common Test suites...
%%% otp_doctest_SUITE:
%%% otp_doctest_SUITE ==> doctests: FAILED
%%% otp_doctest_SUITE ==> {{badmatch,foo},
 [{erl_eval,expr,6,[{file,"erl_eval.erl"},{line,670}]},
  {shell_docs_test,run_tests,2,[{file,"shell_docs_test.erl"},{line,198}]},
  {lists,foldl,3,[{file,"lists.erl"},{line,2150}]},
  {shell_docs_test,test,2,[{file,"shell_docs_test.erl"},{line,153}]},
  {shell_docs_test,parse_and_run,3,[{file,"shell_docs_test.erl"},{line,137}]},
  {shell_docs_test,'-parse_and_run/3-lc$^0/1-0-',3,
                   [{file,"shell_docs_test.erl"},{line,133}]},
  {shell_docs_test,'-module/2-lc$^0/1-0-',3,
                   [{file,"shell_docs_test.erl"},{line,122}]},
  {shell_docs_test,module,2,[{file,"shell_docs_test.erl"},{line,123}]}]}

cc @garazdawi

Copy link
Contributor

github-actions bot commented Feb 13, 2025

CT Test Results

    3 files    392 suites   1h 16m 2s ⏱️
2 306 tests 2 063 ✅ 242 💤 1 ❌
7 299 runs  7 005 ✅ 293 💤 1 ❌

For more details on these failures, see this check.

Results for commit d51a975.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@williamthome williamthome changed the base branch from master to maint February 13, 2025 13:25
@williamthome williamthome changed the base branch from maint to master February 13, 2025 13:25
@williamthome
Copy link
Contributor Author

I think this fix should be in the maint branch, but I changed the base branch and a bunch of commits appeared in this PR.

@IngelaAndin IngelaAndin added the team:VM Assigned to OTP team VM label Feb 17, 2025
Copy link
Contributor

@bjorng bjorng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your pull request.

Please add a test case to beam_doc_SUITE in the compiler application.

@michalmuskala
Copy link
Contributor

As a side point, I wonder if rebar3 should switch how it uses cover, to just compiling the code in the first place with the appropriate flags, rather than dynamically recompiling it - it's much faster and avoids issues like this - it was one of the reasons to add the new coverage system - it doesn't require dynamic recompilation.

@williamthome williamthome force-pushed the fix/code-get-doc-cover-compiled branch from e167d95 to 8d3113e Compare February 24, 2025 20:09
@williamthome
Copy link
Contributor Author

Please add a test case to beam_doc_SUITE in the compiler application.

Done.

@williamthome williamthome requested a review from bjorng February 24, 2025 23:01
@williamthome williamthome force-pushed the fix/code-get-doc-cover-compiled branch from 8d3113e to b78520f Compare February 25, 2025 02:31
@williamthome williamthome force-pushed the fix/code-get-doc-cover-compiled branch from b78520f to d51a975 Compare February 25, 2025 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team:VM Assigned to OTP team VM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants