Reuse existing FormatCallSiteExpression helper for AreEqual/AreNotEqual#8316
Merged
Merged
Conversation
Removes the duplicate FormatBinaryCallSiteExpression helper (and LineBreakChars field) added in #8231 and routes Assert.AreEqual / Assert.AreNotEqual through the existing 2-arg internal FormatCallSiteExpression overload. This aligns call-site formatting with Assert.AreSame / Assert.Contains / Assert.AreEquivalent etc.: * When one of the two captured expressions is empty/whitespace, the call site is still rendered with a placeholder for the empty side (was: entire call site dropped). * Multiline expressions are normalized through the shared NormalizeCallSitePlaceholder helper instead of a parallel LineBreakChars/IsMultiline implementation. Addresses #8231 (comment). Co-authored-by: Copilot <[email protected]>
Evangelink
commented
May 18, 2026
Member
Author
Evangelink
left a comment
There was a problem hiding this comment.
Code Review — PR #8316
✅ 21/21 dimensions clean — no findings.
| # | Dimension | Verdict |
|---|---|---|
| 1 | Algorithmic Correctness | ✅ LGTM |
| 2 | Threading & Concurrency | ⏭️ N/A |
| 3 | Security & IPC | ⏭️ N/A |
| 4 | Public API & Binary Compatibility | ✅ LGTM |
| 5 | Performance & Allocations | ✅ LGTM |
| 6 | Cross-TFM Compatibility | ✅ LGTM |
| 7 | Resource & IDisposable Management | ⏭️ N/A |
| 8 | Defensive Coding at Boundaries | ✅ LGTM |
| 9 | Localization & Resources | ⏭️ N/A |
| 10 | Test Isolation | ⏭️ N/A |
| 11 | Assertion Quality | ⏭️ N/A |
| 12 | Flakiness Patterns | ⏭️ N/A |
| 13 | Test Completeness & Coverage | ✅ LGTM |
| 14 | Data-Driven Test Coverage | ⏭️ N/A |
| 15 | Code Structure & Simplification | ✅ LGTM |
| 16 | Naming & Conventions | ✅ LGTM |
| 17 | Documentation Accuracy | ✅ LGTM |
| 18 | Analyzer & Code Fix Quality | ⏭️ N/A |
| 19 | IPC Wire Compatibility | ⏭️ N/A |
| 20 | Build Infrastructure & Dependencies | ⏭️ N/A |
| 21 | Scope & PR Discipline | ✅ LGTM |
Summary
The change is a clean, well-reasoned deduplication:
- Correctness:
FormatCallSiteExpression(string,string,string,string,string)correctly handles the new semantics — both-empty →null; one-empty → placeholder; multiline → placeholder. Pre-bracketed literals like"<expected>"pass throughNormalizeCallSitePlaceholderunchanged. ✅ - Performance: Marginally better —
IsMultilineuses twoIndexOf(char)calls (zero-alloc) vs the oldIndexOfAny(char[])which allocated achar[]on pre-.NET 8 targets. ✅ - Cross-TFM:
IsMultilinealready usesIndexOf(char)explicitly (notstring.Contains(char)) fornetstandard2.0/net462compatibility. ✅ - Test coverage:
AssertTests.FormatCallSiteExpressionTests.cscovers the behavior-changing edge case (one-empty-one-non-empty → placeholder, not null). ✅ - API compat: Both removed members were
private static— no public surface affected. ✅
Generated by Expert Code Review (on open) for issue #8316 · ● 10.9M
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.
Follow-up to #8231 addressing #8231 (comment).
The new
FormatBinaryCallSiteExpressionhelper (plus itsLineBreakCharsfield) introduced in #8231 duplicated the existing 2-arg internalFormatCallSiteExpressionoverload and had subtly different semantics:<placeholder>for the empty side.LineBreakChars/IndexOfAnynewline-detection in parallel with the existingIsMultiline/NormalizeCallSitePlaceholderinfrastructure.This PR:
FormatBinaryCallSiteExpressionand theLineBreakCharsfield fromAssert.cs.Assert.AreEqualandAssert.AreNotEqualfailure reporting through the existingFormatCallSiteExpression(string, string, string, string, string)overload, matching the call sites already used byAssert.AreSame,Assert.AreNotSame,Assert.Contains,Assert.AreEquivalent,Assert.StartsWith/EndsWith,Assert.MatchesRegex, etc.Behavioral notes
For the typical case where both
[CallerArgumentExpression]values are captured normally, the rendered call site is identical (e.g.Assert.AreEqual(expected, actual)).The difference only shows up in the rare edge case where one side's caller-argument expression is empty (e.g. used through reflection / hand-built call) - the call site is now still rendered with
<expected>/<actual>placeholders, consistent with the other binary assertions, instead of being suppressed.Validation
.\build.cmd -c Release: succeeded.dotnet test test\UnitTests\TestFramework.UnitTests\TestFramework.UnitTests.csproj -c Release --no-build: only the same 2 pre-existingAreAllDistinct_*WithComparer_HasDuplicate_ShouldFailfailures observed onmainremain (unrelated to this change).