-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Coverage instrumentation of unit tests also instruments a closure added by #[test] #120046
Copy link
Copy link
Closed
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-code-coverageArea: Source-based code coverage (-Cinstrument-coverage)Area: Source-based code coverage (-Cinstrument-coverage)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-code-coverageArea: Source-based code coverage (-Cinstrument-coverage)Area: Source-based code coverage (-Cinstrument-coverage)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Consider this source file from the coverage test suite:
rust/tests/coverage/test_harness.rs
Lines 9 to 10 in 6bf600b
When we instrument this file for coverage, we generate coverage mappings for
my_testas expected. However, we also generate coverage mappings for a mysterious closure insidemy_test:rust/tests/coverage/test_harness.cov-map
Lines 9 to 15 in 6bf600b
This closure turns out to have been added by the builtin macro that expands
#[test]attributes.Adding coverage instrumentation to this closure is not useful, and we should not be doing it.
Right now this only causes minor problems in the final coverage reports, because coverage for the closure shows up on its own line with the span of the attribute. But while working on some other changes to how we handle macro-expanded closure bodies, I found that some of my changes had the side-effect of causing these test closures to show up and start interfering with the reports.
We should have some way for the coverage instrumentor to know that it should ignore closures introduced by
#[test]attributes, and not instrument them at all.