Skip to content

Improve pattern matching branch detection and docs - #1979

Merged
Bertk merged 5 commits into
coverlet-coverage:masterfrom
Bertk:fix-branch-coverage
Jul 3, 2026
Merged

Bertk merged 5 commits into
coverlet-coverage:masterfrom
Bertk:fix-branch-coverage

Conversation

@Bertk

@Bertk Bertk commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

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

Copilot AI review requested due to automatic review settings July 2, 2026 09:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 CecilSymbolHelper branch filtering for pattern-matching or so synthetic branches don’t inflate/deflate branch coverage.
  • Adds a focused unit test asserting text is "a" or "b" matches the branch-point count of text == "a" || text == "b" and stays mapped to the source line.
  • Normalizes module path comparisons in InstrumentationHelper to avoid .pdb restore 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).

Comment thread src/coverlet.core/Symbols/CecilSymbolHelper.cs Outdated
Comment thread src/coverlet.core/Helpers/InstrumentationHelper.cs Outdated
Comment thread .github/copilot-instructions.md Outdated
Comment thread .github/copilot-instructions.md
Comment thread .github/copilot-instructions.md
Comment thread .github/copilot-instructions.md
Comment thread .github/copilot-instructions.md Outdated
Comment thread .github/copilot-instructions.md Outdated
Comment thread .github/copilot-instructions.md Outdated
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
Bertk force-pushed the fix-branch-coverage branch from e0fcee7 to 057d6a4 Compare July 2, 2026 15:12
Bertk added 4 commits July 3, 2026 09:19
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.
@Bertk
Bertk merged commit 330b1af into coverlet-coverage:master Jul 3, 2026
10 checks passed
@Bertk
Bertk deleted the fix-branch-coverage branch July 3, 2026 10:25
This was referenced Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] When using "is" with "or" in pattern matching, branch coverage is lower than normal

2 participants