Improve pattern matching branch detection and docs - #1979
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses branch-coverage inaccuracies for C# pattern-matching or expressions (Issue #1969) by refining Coverlet’s IL heuristics to avoid counting compiler-synthetic branches, adds a targeted unit test to prevent regressions, and updates instrumentation restore logic and contributor/agent guidance docs.
Changes:
- Refines
CecilSymbolHelperbranch filtering for pattern-matchingorso synthetic branches don’t inflate/deflate branch coverage. - Adds a focused unit test asserting
text is "a" or "b"matches the branch-point count oftext == "a" || text == "b"and stays mapped to the source line. - Normalizes module path comparisons in
InstrumentationHelperto avoid.pdbrestore overwrite issues; updates Copilot instructions content.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
| test/coverlet.core.tests/Symbols/CecilSymbolHelperTests.cs | Adds regression test for Issue #1969 ensuring pattern-matching or yields the expected branch point count and source mapping. |
| src/coverlet.core/Symbols/CecilSymbolHelper.cs | Updates pattern-matching or branch-skipping heuristic to avoid reporting synthetic branches. |
| src/coverlet.core/Helpers/InstrumentationHelper.cs | Adjusts “currently running assembly” detection to prevent locked .pdb overwrite during restore. |
| .github/copilot-instructions.md | Updates contributor/agent guidelines (notably around documentation creation and testing rules). |
Added test and sample for C# pattern matching 'or' to ensure 100% branch coverage reporting. Updated copilot-instructions.md with new guidelines for analysis limits, pattern matching or rules, Moq usage best practices, logger verification checklist, and stricter documentation creation requirements.
Bertk
force-pushed
the
fix-branch-coverage
branch
from
July 2, 2026 15:12
e0fcee7 to
057d6a4
Compare
Replaced the strict assertion on exact branch hit counts with a more general check to ensure all branches have at least one hit. This improves test robustness by not depending on specific hit values.
Adjust CoverageTests.PatternMatchingOr to handle differing branch counts and paths between Debug and Release builds. Uses TestUtils.GetAssemblyBuildConfiguration to select the correct assertions for each configuration.
Adjust CecilSymbolHelperTests to assert different branch point counts for pattern matching 'or' expressions based on Debug or Release build configuration, using TestUtils.GetAssemblyBuildConfiguration(). This ensures test reliability across build types.
This was referenced Sep 27, 2026
This was referenced Sep 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refined branch detection for C# pattern matching 'or' to avoid synthetic branches, added targeted tests, and clarified documentation guidelines (including doc creation rules and formatting) in copilot-instructions.md. Also fixed module path normalization in InstrumentationHelper to prevent .pdb overwrite issues.
#1969