Skip to content

Apply structured assertion messages (RFC 012) to Assert.MatchesRegex / DoesNotMatchRegex#8259

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

Apply structured assertion messages (RFC 012) to Assert.MatchesRegex / DoesNotMatchRegex#8259
Evangelink merged 5 commits into
mainfrom
dev/amauryleve/assert-matches-rfc012

Conversation

@Evangelink
Copy link
Copy Markdown
Member

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

Output format

Assert.MatchesRegex(new Regex(""^foo""), ""hello""):

Assertion failed. Expected string to match the specified regular expression.

expected pattern: ""^foo""
actual:           ""hello""

Assert.MatchesRegex(new Regex(""^foo""), ""hello"")

Assert.DoesNotMatchRegex(new Regex(""world""), ""hello world"", ""value should not match""):

Assertion failed. Expected string to not match the specified regular expression.
value should not match

unexpected pattern: ""world""
actual:             ""hello world""

Assert.DoesNotMatchRegex(new Regex(""world""), ""hello world"")

Notes

  • Adds MatchesRegexFailedSummary / DoesNotMatchRegexFailedSummary resource entries (XLF files regenerated via UpdateXlf).
  • Removes the now-unused BuildUserMessageForPatternExpressionAndValueExpression helper from Assert.cs because the call-site is now reconstructed by FormatCallSiteExpression.
  • StringAssert.Matches / StringAssert.DoesNotMatch are intentionally unchanged and continue to use FrameworkMessages.IsMatchFail / IsNotMatchFail.

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

…/ DoesNotMatchRegex

Migrates Assert.MatchesRegex / Assert.DoesNotMatchRegex to the structured assertion message format defined in RFC 012, following the patterns used by the previously migrated string predicate assertions.

The evidence block carries the expected/unexpected pattern (rendered as a string literal so it copy-pastes cleanly) and the actual string. Removes the now-unused BuildUserMessageForPatternExpressionAndValueExpression helper from Assert.cs because the call-site is now reconstructed via FormatCallSiteExpression. StringAssert.Matches / DoesNotMatch are unaffected and continue to use FrameworkMessages.IsMatchFail / IsNotMatchFail.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 15, 2026 13:34
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

Rolls forward the RFC 012 “Structured Assertion Messages” migration by converting Assert.MatchesRegex and Assert.DoesNotMatchRegex to the structured, multi-line failure format and wiring new localized summary resources.

Changes:

  • Migrated Assert.MatchesRegex / Assert.DoesNotMatchRegex failure paths to StructuredAssertionMessage + EvidenceBlock + call-site rendering.
  • Added new FrameworkMessages.*FailedSummary resource entries and regenerated corresponding XLF entries.
  • Removed the now-unused BuildUserMessageForPatternExpressionAndValueExpression helper from Assert.cs.
Show a summary per file
File Description
src/TestFramework/TestFramework/Assertions/Assert.Matches.cs Converts regex assertions to structured assertion messages with evidence blocks and call-site formatting.
src/TestFramework/TestFramework/Assertions/Assert.cs Removes unused user-message builder helper now that call-sites are formatted via FormatCallSiteExpression.
src/TestFramework/TestFramework/Resources/FrameworkMessages.resx Adds MatchesRegexFailedSummary and DoesNotMatchRegexFailedSummary resource strings.
src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf Adds new trans-units for the two new summary resource keys.
src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf Adds new trans-units for the two new summary resource keys.
src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf Adds new trans-units for the two new summary resource keys.
src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf Adds new trans-units for the two new summary resource keys.
src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf Adds new trans-units for the two new summary resource keys.
src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf Adds new trans-units for the two new summary resource keys.
src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf Adds new trans-units for the two new summary resource keys.
src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf Adds new trans-units for the two new summary resource keys.
src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf Adds new trans-units for the two new summary resource keys.
src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf Adds new trans-units for the two new summary resource keys.
src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf Adds new trans-units for the two new summary resource keys.
src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf Adds new trans-units for the two new summary resource keys.
src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf Adds new trans-units for the two new summary resource keys.

Copilot's findings

  • Files reviewed: 16/16 changed files
  • Comments generated: 2

Comment thread src/TestFramework/TestFramework/Assertions/Assert.Matches.cs
Comment thread src/TestFramework/TestFramework/Assertions/Assert.Matches.cs
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 #8259: Structured assertion messages for Assert.MatchesRegex / DoesNotMatchRegex

This PR continues the RFC 012 rollout in a clean, consistent manner. The implementation faithfully mirrors the pattern established by prior migrations (#8170, #8187, #8210, #8214, #8258).

Dimension Result Severity
Algorithmic Correctness ✅ LGTM
Threading & Concurrency ✅ N/A (no shared state)
Security ✅ N/A
Public API & Binary Compatibility ✅ LGTM
Performance & Allocations ✅ LGTM
Cross-TFM Compatibility ✅ LGTM
Resource & IDisposable ✅ N/A
Localization & Resources ✅ LGTM — XLF files regenerated via the UpdateXlf automated build target
Test Completeness ⚠️ ISSUE MODERATE
Code Structure ✅ LGTM
Naming & Conventions ✅ LGTM
Documentation Accuracy ✅ LGTM
Scope & PR Discipline ✅ LGTM

Notable design consistency

WithExpectedAndActual(patternText, actualText) is called in ReportAssertDoesNotMatchRegexFailed, storing the (unwanted) pattern as AssertFailedException.ExpectedText. This is consistent with how other DoesNot* methods (e.g. DoesNotContain, DoesNotStartWith) handle the same property in this codebase — the evidence block labels ("unexpected pattern:" / "actual:") provide the human-readable semantics.

Single finding

Test coverage gap (MODERATE): No unit tests were added for the new structured failure message paths. See the inline comment on line 163 of Assert.Matches.cs for details and recommendations.

Generated by Expert Code Review (on open) for issue #8259 · ● 14.5M

Comment thread src/TestFramework/TestFramework/Assertions/Assert.Matches.cs
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>
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, fixed the conflicts, regenerated the FrameworkMessages XLF files, and committed the merge resolution in 63e9c64.

Copilot AI review requested due to automatic review settings May 16, 2026 08:37
@Evangelink Evangelink review requested due to automatic review settings May 16, 2026 08:37
@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>
Copy link
Copy Markdown
Contributor

Copilot AI commented May 16, 2026

@copilot resolve the merge conflicts in this pull request

Resolved. I merged the latest origin/main, fixed the new conflicts, and committed the merge resolution in 246d348.

Copilot AI review requested due to automatic review settings May 16, 2026 11:55
@Evangelink Evangelink review requested due to automatic review settings May 16, 2026 11:55
These string-predicate helpers (substring, prefix, suffix) are no longer referenced after the structured assertion message refactors landed on main, and IDE0051 is enforced as an error on Linux/macOS.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 16, 2026 13:48
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.

Copilot's findings

Comments suppressed due to low confidence (1)

src/TestFramework/TestFramework/Assertions/Assert.Matches.cs:149

  • Same issue as above: [DoesNotReturn] is not accurate because ReportAssertFailed(StructuredAssertionMessage) returns in AssertScope mode. Please remove the attribute (or ensure the method truly does not return).
    [DoesNotReturn]
    private static void ReportAssertDoesNotMatchRegexFailed(Regex pattern, string value, string? userMessage, string patternExpression, string valueExpression)
    {
  • Files reviewed: 17/17 changed files
  • Comments generated: 2

Comment thread src/TestFramework/TestFramework/Assertions/Assert.Matches.cs
@Evangelink Evangelink merged commit 6bba519 into main May 16, 2026
17 of 21 checks passed
@Evangelink Evangelink deleted the dev/amauryleve/assert-matches-rfc012 branch May 16, 2026 14:14
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.

4 participants