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

Merged
merged 1 commit into from
Feb 27, 2025

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 14m 23s ⏱️
2 305 tests 2 063 ✅ 241 💤 1 ❌
7 298 runs  7 005 ✅ 292 💤 1 ❌

For more details on these failures, see this check.

Results for commit 06adfb2.

♻️ 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 2 times, most recently from b78520f to d51a975 Compare February 25, 2025 02:34
@bjorng
Copy link
Contributor

bjorng commented Feb 25, 2025

I pushed a fixup commit that fixed a few issues. If you agree, please squash the commits.

  • A test case that changes the working directory is usually not safe to run in a group concurrently with other test cases. For me, one to four test cases failed each time I ran beam_doc_SUITE.
  • If Cover is already running, the test case must be skipped. We often run the compiler tests with Cover enabled.
  • Cover must be stopped when done, irregardless of whether the test case failed or not.

@williamthome williamthome force-pushed the fix/code-get-doc-cover-compiled branch from 4a5efd6 to 81c879a Compare February 25, 2025 15:41
@williamthome
Copy link
Contributor Author

I pushed a fixup commit that fixed a few issues. If you agree, please squash the commits.

  • A test case that changes the working directory is usually not safe to run in a group concurrently with other test cases. For me, one to four test cases failed each time I ran beam_doc_SUITE.
  • If Cover is already running, the test case must be skipped. We often run the compiler tests with Cover enabled.
  • Cover must be stopped when done, irregardless of whether the test case failed or not.

Agree and squashed. Thank you for the fix and explanation!

bjorng
bjorng previously approved these changes Feb 26, 2025
@bjorng bjorng added the testing currently being tested, tag is used by OTP internal CI label Feb 26, 2025
@bjorng
Copy link
Contributor

bjorng commented Feb 26, 2025

Added to our daily builds.

@bjorng bjorng removed the testing currently being tested, tag is used by OTP internal CI label Feb 26, 2025
@bjorng
Copy link
Contributor

bjorng commented Feb 26, 2025

I forgot to run Dialyzer before I pushed my suggestion for simpler implementation. It turns out that one clause will never match. I've pushed a new fixup commit. Please squash.

@williamthome williamthome force-pushed the fix/code-get-doc-cover-compiled branch from 7a39161 to 06adfb2 Compare February 26, 2025 12:11
@williamthome
Copy link
Contributor Author

Please squash.

Done.

@bjorng bjorng added the testing currently being tested, tag is used by OTP internal CI label Feb 26, 2025
@bjorng bjorng merged commit 88a7cc6 into erlang:master Feb 27, 2025
24 of 26 checks passed
@bjorng
Copy link
Contributor

bjorng commented Feb 27, 2025

Thanks for your pull request.

@williamthome williamthome deleted the fix/code-get-doc-cover-compiled branch February 27, 2025 16:09
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 testing currently being tested, tag is used by OTP internal CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants