-
Notifications
You must be signed in to change notification settings - Fork 18.5k
cmd/cover: exclude commented-out code from coverage instrumentation #76692
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
base: master
Are you sure you want to change the base?
cmd/cover: exclude commented-out code from coverage instrumentation #76692
Conversation
|
This PR (HEAD: 48b76a6) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/726800. Important tips:
|
48b76a6 to
801c8ec
Compare
|
Message from Gopher Robot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/726800. |
|
This PR (HEAD: 801c8ec) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/726800. Important tips:
|
|
Message from Alan Donovan: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/726800. |
|
This PR (HEAD: f740d24) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/726800. Important tips:
|
|
Message from Rudy Regazzoni: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/726800. |
|
Message from Alan Donovan: Patch Set 3: (5 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/726800. |
Add logic to exclude purely commented lines from coverage instrumentation.
When instrumenting Go code for coverage, the cover tool now identifies
and excludes lines that contain only comments from coverage blocks.
This prevents commented-out code from being reported as "uncovered"
in coverage reports, which can be misleading.
The implementation adds a splitBlockByComments function that parses
source code character by character to identify segments containing
executable code versus segments containing only comments. The
addCounters function now uses this to create coverage counters only
for segments that contain actual executable code.
The parser correctly handles:
This improves the accuracy of coverage reports by ensuring that
commented-out code, TODOs, and documentation comments don't inflate
the count of uncovered lines.
Fixes #22545