Skip to content

Apply structured assertion messages (RFC 012) to Assert.IComparable family#8260

Merged
Evangelink merged 3 commits into
mainfrom
dev/amauryleve/assert-icomparable-rfc012
May 16, 2026
Merged

Apply structured assertion messages (RFC 012) to Assert.IComparable family#8260
Evangelink merged 3 commits into
mainfrom
dev/amauryleve/assert-icomparable-rfc012

Conversation

@Evangelink
Copy link
Copy Markdown
Member

Continues the rollout of RFC 012 — Structured Assertion Messages by migrating the Assert IComparable family to the structured-message format. Follows the patterns established by previously merged work (#8170, #8187, #8210, #8214) and the in-flight #8258 (StartsWith/EndsWith) and #8259 (MatchesRegex/DoesNotMatchRegex).

Migrates: Assert.IsGreaterThan, Assert.IsGreaterThanOrEqualTo, Assert.IsLessThan, Assert.IsLessThanOrEqualTo, Assert.IsPositive, Assert.IsNegative.

Output format

Assert.IsGreaterThan(10, 5, ""A Message""):

Assertion failed. Expected value to be greater than the lower bound.
A Message

lower bound: 10
actual:      5

Assert.IsGreaterThan(10, 5)

Assert.IsLessThanOrEqualTo(5, 10, ""A Message""):

Assertion failed. Expected value to be less than or equal to the upper bound.
A Message

upper bound: 5
actual:      10

Assert.IsLessThanOrEqualTo(5, 10)

Assert.IsPositive(-5, ""A Message""):

Assertion failed. Expected value to be positive.
A Message

expected: > 0
actual:   -5

Assert.IsPositive(-5)

Notes

  • Adds IsGreaterThanFailedSummary / IsGreaterThanOrEqualToFailedSummary / IsLessThanFailedSummary / IsLessThanOrEqualToFailedSummary / IsPositiveFailedSummary / IsNegativeFailedSummary resource entries (XLF files regenerated via UpdateXlf).
  • Removes the now-unused BuildUserMessageForLowerBoundExpression* / BuildUserMessageForUpperBoundExpression* / BuildUserMessageForValueExpression helpers from Assert.cs.
  • Updates the message-format tests in AssertTests.IComparableTests.cs to assert against the new layout.

Validation

  • dotnet build src/TestFramework/TestFramework/TestFramework.csproj -c Debug — clean.
  • dotnet test test/UnitTests/TestFramework.UnitTests/TestFramework.UnitTests.csproj -c Debug — 3535/3535 passed.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

…amily

Migrates Assert.IsGreaterThan / IsGreaterThanOrEqualTo / IsLessThan / IsLessThanOrEqualTo / IsPositive / IsNegative to the structured assertion message format defined in RFC 012.

The bound comparisons use 'lower bound:' / 'upper bound:' labels next to 'actual:'. The IsPositive / IsNegative assertions use 'expected: > 0' / 'expected: < 0' for symmetry with how WithExpectedAndActual is consumed by AssertFailedException.ExpectedText / ActualText.

Removes the now-unused BuildUserMessageForLowerBoundExpression* / UpperBoundExpression* / ValueExpression helpers from Assert.cs (the call-site is now reconstructed via FormatCallSiteExpression).

Updates the affected tests in AssertTests.IComparableTests.cs to match the new message layout.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 15, 2026 13:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Continues the RFC 012 rollout by migrating the Assert IComparable family (IsGreaterThan, IsGreaterThanOrEqualTo, IsLessThan, IsLessThanOrEqualTo, IsPositive, IsNegative) to the structured assertion message format.

Changes:

  • Replaced legacy single-line Report*Failed helpers with ReportComparisonFailed/ReportSignFailed that build a StructuredAssertionMessage (summary, evidence block, expected/actual metadata, and call-site expression).
  • Added six *FailedSummary resource entries (FrameworkMessages.resx + all .xlf files updated via UpdateXlf).
  • Removed now-unused BuildUserMessageForLowerBound/UpperBound/ValueExpression helpers, consolidated NaN handling for IsPositive/IsNegative into a single or pattern, and updated AssertTests.IComparableTests expectations.
Show a summary per file
File Description
src/TestFramework/TestFramework/Assertions/Assert.IComparable.cs Rewires the six assertions to use the structured message helpers.
src/TestFramework/TestFramework/Assertions/Assert.cs Removes now-unused BuildUserMessageFor* helpers.
src/TestFramework/TestFramework/Resources/FrameworkMessages.resx Adds six *FailedSummary resource strings.
src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.*.xlf Regenerated XLFs for the new resource entries.
test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs Updates the six *ShouldThrowWithMessage tests to the new layout.

Copilot's findings

  • Files reviewed: 17/17 changed files
  • Comments generated: 0

Copy link
Copy Markdown
Member Author

@Evangelink Evangelink left a comment

Choose a reason for hiding this comment

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

Review Summary — PR #8260 (Assert.IComparable → RFC 012 structured messages)

# Dimension Verdict
1 Algorithmic Correctness ✅ LGTM (bonus: pre-existing "Assert.IsLessThan" typo in IsLessThanOrEqualTo reporter fixed)
2 Threading & Concurrency ✅ N/A
3 Security & IPC Contract Safety ✅ 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 🟡 1 MODERATE
10 Test Isolation ✅ LGTM
11 Assertion Quality ✅ LGTM
12 Flakiness Patterns ✅ LGTM
13 Test Completeness & Coverage ✅ LGTM
14 Data-Driven Test Coverage ✅ LGTM
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 ✅ LGTM
21 Scope & PR Discipline ✅ LGTM

✅ 19/21 dimensions clean (2 N/A).


Finding

  • [MODERATE] Orphaned resource keys in FrameworkMessages.resx — The six old Is*FailMsg keys (IsGreaterThanFailMsg, IsGreaterThanOrEqualToFailMsg, IsLessThanFailMsg, IsLessThanOrEqualToFailMsg, IsPositiveFailMsg, IsNegativeFailMsg) are still present in the .resx and all XLF locale files even though no code references them any longer. Translators will be asked to localize dead strings. Remove these entries (.resx + all XLF trans-units) before merging.

Generated by Expert Code Review (on open) for issue #8260 · ● 29.6M

Comment thread src/TestFramework/TestFramework/Resources/FrameworkMessages.resx
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Evangelink
Copy link
Copy Markdown
Member Author

@copilot resolve the merge conflicts in this pull request

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 16, 2026 08:34
@Evangelink Evangelink review requested due to automatic review settings May 16, 2026 08:34
Copy link
Copy Markdown
Contributor

Copilot AI commented May 16, 2026

@copilot resolve the merge conflicts in this pull request

Resolved. I merged origin/main into this branch and fixed the conflict in FrameworkMessages.resx so both the IComparable structured-message summaries and the StartsWith/EndsWith summaries are preserved. Addressed in commit 60738e7.

@Evangelink Evangelink merged commit c210f0d into main May 16, 2026
10 checks passed
@Evangelink Evangelink deleted the dev/amauryleve/assert-icomparable-rfc012 branch May 16, 2026 09:22
Copilot AI added a commit that referenced this pull request May 16, 2026
…icts with IComparable RFC 012 (#8260)

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants