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

Add #[no_coverage] tests for nested functions #92695

Merged
merged 1 commit into from
Feb 8, 2022

Conversation

Swatinem
Copy link
Contributor

@Swatinem Swatinem commented Jan 9, 2022

I was playing around a bit trying to figure out how #[no_coverage] behaves for nested functions and thought I might as well add this as a testcase.

The "nesting covered fn inside not covered fn" case looks pretty much as expected.

The "nesting not covered fn inside a covered fn" case however seems a bit counterintuitive.
Essentially the region of the outer function "covers" its whole lexical range. And the inner function does not generate any region at all. 🤷🏻‍♂️

r? @richkadel

@camelid
Copy link
Member

camelid commented Jan 25, 2022

r? rust-lang/compiler

@camelid camelid added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) labels Jan 25, 2022
Copy link
Contributor

@richkadel richkadel left a comment

Choose a reason for hiding this comment

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

Sorry for the delayed reply. I just moved to a new city and house so I was out of office for a while.

I added a couple of comments.

Worth noting, I don't think #[no_coverage] is widely used, at the current time. It has at least one specific use case (in the standard library), which isn't affected by this bug.

Nevertheless, it's something we should look into.

If you haven't already, can you file an "issue" with this example, so we can track a future fix to the known issue?

cc: @tmandry @wesleywiser

50| 1| fn inner_not_covered(is_true: bool) {
51| 1| if is_true {
52| 1| println!("called but not covered");
53| 1| } else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, this looks like a bug, at least in how #[no_coverage] works.

@Swatinem
Copy link
Contributor Author

I don't think #[no_coverage] is widely used, at the current time.

I was experimenting with adding that attr to all #[test] functions when desugaring, however I got stuck figuring out how to deal with that attr being nightly-only :-D

Another interesting this that this test does not cover: How do nested functions look with normal covered/uncovered ranges, independently of #[no_coverage].

@michaelwoerister
Copy link
Member

I don't really know code coverage. @richkadel, who do you think would be a good reviewer for this?

@richkadel
Copy link
Contributor

@tmandry or @wesleywiser could review this.

Another interesting this that this test does not cover: How do nested functions look with normal covered/uncovered ranges, independently of #[no_coverage].

@Swatinem - Yes, I think you should add that to the test, for comparison.

And add a FIXME comment to the test referencing your issue number, if you haven't done that yet.

Thanks!

@wesleywiser
Copy link
Member

r? @wesleywiser

@wesleywiser
Copy link
Member

Thanks for adding these tests! I agree with @richkadel, it would be good to have that additional test case mentioned added as well. If you have time to do that, great! If not, let me know and I'll try to add it myself.

@Swatinem
Copy link
Contributor Author

Swatinem commented Feb 7, 2022

Rebased and added a comment linking to the issue, and another testcase for nested fns without any #[no_coverage] annotation.

@wesleywiser
Copy link
Member

Thanks @Swatinem!

@bors r+

@bors
Copy link
Contributor

bors commented Feb 7, 2022

📌 Commit fe9271a has been approved by wesleywiser

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 7, 2022
67| 1| println!("called and covered");
68| 1| } else {
69| 0| println!("absolutely not covered");
70| 0| }
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding this @Swatinem !!

Interesting. I'm kind of surprised to see zeros here on lines 69-70 (correctly), given the reported issue with no_coverage on inner functions. LLVM tools must recognize the overlapping inner function range and, in that case, only reports coverage for the inner function's code range.

(I'm fairly certain there were tests for inner functions, so I'm happy to see at least that part is doing what is expected. It wasn't a total oversight.)

IMO, there's not a strong use case for no_coverage of inner functions, so while it is still a bug, it isn't an urgent one. And the no_coverage attribute is not stabilized (at this point).

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 8, 2022
…askrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#86497 (Add {floor,ceil}_char_boundary methods to str)
 - rust-lang#92695 (Add `#[no_coverage]` tests for nested functions)
 - rust-lang#93521 (Fix hover effects in sidebar)
 - rust-lang#93568 (Include all contents of first line of scraped item in Rustdoc)
 - rust-lang#93569 (rustdoc: correct unclosed HTML tags as generics)
 - rust-lang#93672 (update comment wrt const param defaults)
 - rust-lang#93715 (Fix horizontal trim for block doc comments)
 - rust-lang#93721 (rustdoc: Special-case macro lookups less)
 - rust-lang#93728 (Add in ValuePair::Term)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 6024426 into rust-lang:master Feb 8, 2022
@rustbot rustbot added this to the 1.60.0 milestone Feb 8, 2022
@Swatinem Swatinem deleted the cover-nested branch May 18, 2022 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants