feat: support AssertionResult<T> in GenerateAssertion for terminal assertions#4843
Merged
feat: support AssertionResult<T> in GenerateAssertion for terminal assertions#4843
Conversation
…sertions Adds support for [GenerateAssertion] methods that return AssertionResult<T> or Task<AssertionResult<T>>, enabling generated assertions that return a value when awaited (terminal assertions). Previously this required hand-writing the entire assertion class. Closes #4829 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. This PR introduces a well-designed feature for terminal assertions that return typed values. The implementation:
|
- Regenerate all .verified.txt files to match current generator output - Fix RefStructParameter test: add PreprocessorSymbols support to RunTestOptions and pass NET6_0_OR_GREATER when testing ref struct parameter handling - Simplify ContainsMessage test data to use expression body (required for InlineMethodBody with ref struct parameters) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The assertions public API tests were failing because the new AssertionResult<T> type was added but the verified snapshot files were not updated to reflect this API addition. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced Feb 18, 2026
This was referenced Feb 19, 2026
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.
Summary
AssertionResult<T>readonly struct for assertions that return a value when awaited (terminal assertions)[GenerateAssertion]source generator to recognizeAssertionResult<T>andTask<AssertionResult<T>>return types_resultcapture field,new GetAwaiter()override, andExecuteAndReturnResultAsync()to enablestring matched = await Assert.That(items).ContainsMatch("foo")Closes #4829
Usage
Test plan
AssertionResult<T>return typeTask<AssertionResult<T>>return type_resultfield,new GetAwaiter<T>(), and unwrapping logicMethodAssertionGeneratorTestspass without regressionTUnit.Assertionsbuilds cleanly across all target frameworks (net8.0, net9.0, net10.0, netstandard2.0)🤖 Generated with Claude Code