Assert.That: additional test cases for object-typed sub-expressions (stacks on #8307)#8308
Conversation
|
@copilot resolve the merge conflicts in this pull request |
Done in |
|
Pushed 12c8549:
The PR is still draft because (only one entry because the second call mutates the same |
|
@copilot resolve the merge conflicts in this pull request |
Already resolved in |
|
@copilot resolve the merge conflicts in this pull request |
|
@copilot resolve the merge conflicts in this pull request |
Already resolved in |
There are no unresolved merge conflicts on this branch ( |
|
@copilot resolve the merge conflicts in this pull request |
I re-checked the branch: there are no unresolved merge conflicts ( |
…ted reference Resets PR #8308 onto current main and re-adds the unique contribution from @jakubjares as a single test plus its helper types. After PR #8307 was merged via #8306 and PR #8358 added the CA1305 fix, the old branch was hopelessly diverged from main. Instead of trying to thread the needle through 16+ source conflicts, this commit takes main's source/test files verbatim and only adds: * That_TwoCallsReturningSameMutatedReference_DeduplicatesInDetails * Shape (helper) * BoxOfShapes (helper) The test pins down the current UX limitation: when two calls return the SAME mutable reference and the comparison is reference-inequality, the cache stores the same reference for both call expressions; by the time details are extracted the object has been mutated, both slots resolve to the same value, and TryAddExpressionValue's same-value dedupe means only one entry surfaces (`Shape: Circle`). Documenting this behavior gives us a regression guard if we ever decide to improve the diagnostic. Replaces the previous `WithMessage("non")` placeholder with the real expected message. All 76 That_* tests pass. Co-authored-by: Jakub Jareš <me@jakubjares.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
12c8549 to
10450c2
Compare
|
I've reset this branch onto current
Why a reset rather than a merge: this branch was stacked on Marking as ready for review. |
…ted reference Resets PR #8308 onto current main and re-adds the unique contribution from @jakubjares as a single test plus its helper types. After PR #8307 was merged via #8306 and PR #8358 added the CA1305 fix, the old branch was hopelessly diverged from main. Instead of trying to thread the needle through 16+ source conflicts, this commit takes main's source/test files verbatim and only adds: * That_TwoCallsReturningSameMutatedReference_DeduplicatesInDetails * Shape (helper) * BoxOfShapes (helper) The test pins down the current UX limitation: when two calls return the SAME mutable reference and the comparison is reference-inequality, the cache stores the same reference for both call expressions; by the time details are extracted the object has been mutated, both slots resolve to the same value, and TryAddExpressionValue's same-value dedupe means only one entry surfaces (`Shape: Circle`). Documenting this behavior gives us a regression guard if we ever decide to improve the diagnostic. Replaces the previous `WithMessage("non")` placeholder with the real expected message. All 76 That_* tests pass. Co-authored-by: Jakub Jareš <me@jakubjares.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a new unit test to pin down current Assert.That diagnostic behavior when the same mutable reference is returned from multiple side-effecting sub-expressions, leading to deduped “Details” output.
Changes:
- Added a new test asserting the current “Details” output when two calls return the same mutated reference.
- Introduced helper types (
Shape,BoxOfShapes) to reproduce the side-effecting reference scenario.
Show a summary per file
| File | Description |
|---|---|
| test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.That.cs | Adds a regression test (plus helper types) to lock in current Assert.That diagnostics for repeated mutable reference values. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 3
| // method calls return the same mutable reference. The cache stores reference values, so by | ||
| // the time details are extracted both slots point to the post-mutation object; with | ||
| // first-occurrence-by-name and "same value -> dedupe" semantics in TryAddExpressionValue, | ||
| // only one entry surfaces. This is a known UX limitation worth pinning down with a test. |
| // ---- Object-typed sub-expressions: locks down current behavior when two side-effecting | ||
| // method calls return the same mutable reference. The cache stores reference values, so by | ||
| // the time details are extracted both slots point to the post-mutation object; with | ||
| // first-occurrence-by-name and "same value -> dedupe" semantics in TryAddExpressionValue, | ||
| // only one entry surfaces. This is a known UX limitation worth pinning down with a test. |
| Action act = () => Assert.That(() => box.GetValueWithSideEffect() != box.GetValueWithSideEffect()); | ||
|
|
||
| act.Should().Throw<AssertFailedException>() | ||
| .WithMessage( | ||
| """ | ||
| Assert.That(() => box.GetValueWithSideEffect() != box.GetValueWithSideEffect()) failed. |
10450c2 to
ff51120
Compare
Stacks on top of #8307 (
dev/amauryleve/assert-that).Adds an extra test case from @jakubjares exploring
Assert.Thatbehavior when sub-expressions evaluate toobjectreferences (where the diagnostic message can be confusing). The testThat_DoesEvaluateTwice_WhenMethodIsLeaf2and helper types (Shape,BoxOfShapes) were authored on 2025-11-25.Warning
Marked as draft because the new test currently asserts
WithMessage(""""""non""""""), which is clearly a placeholder. The test expectation needs to be updated to the real expected failure message (and the test renamed if appropriate) before this PR is ready for review.Merge notes
This branch was rebased onto
main(commit 6b0bae4). Same resolution strategy as #8307:Assert.That.cs: kept the newEvaluateExpression/ cache logic; adopted main'sStringBuilder.Append(char, int)overload while preserving theMaxConsecutiveParenthesesconstant.FrameworkMessages.resx: keptAssertThatFailedToEvaluatealongside all new RFC 012 summary entries from main;xlffiles regenerated viadotnet msbuild /t:UpdateXlf.[RequiresDynamicCode(...)]attributes with#if NET7_0_OR_GREATERfornetstandard2.0/net462compatibility.Validation
dotnet build src/TestFramework/TestFramework/TestFramework.csproj -c Debug-> clean across netstandard2.0, net462, net8.0, net9.0.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com