ActualValueDelegate and Func are always evaluated#984
Open
manfred-brands wants to merge 3 commits intonunit:masterfrom
Open
ActualValueDelegate and Func are always evaluated#984manfred-brands wants to merge 3 commits intonunit:masterfrom
manfred-brands wants to merge 3 commits intonunit:masterfrom
Conversation
We need to consider their return type. TestDelegate and Action are never evaluated for their return type as they don't have one.
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the analyzer’s “actual type” unwrapping logic so that Func<T> (and related delegate forms) are treated like ActualValueDelegate<T> when determining the type being asserted, aligning analyzer behavior with NUnit’s delegate-evaluation semantics and expanding related test coverage.
Changes:
- Updated
AssertHelper.UnwrapActualTypeto unwrapSystem.Func<T>(and introduced handling forAsyncTestDelegate). - Added
AsyncTestDelegateto the framework constants (and corresponding constants test). - Updated/added analyzer tests to reflect
Func<T>unwrapping behavior (including newFunc<double>/Func<Task<double>>coverage).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/nunit.analyzers/Helpers/AssertHelper.cs | Extends delegate unwrapping to recognize Func<T> (and currently AsyncTestDelegate). |
| src/nunit.analyzers/Constants/NUnitFrameworkConstants.cs | Adds FullNameOfAsyncTestDelegate constant. |
| src/nunit.analyzers.tests/SameAsIncompatibleTypes/SameAsIncompatibleTypesAnalyzerTests.cs | Updates expected outcome for Func<T> “actual” in SameAs analyzer tests. |
| src/nunit.analyzers.tests/NullConstraintUsage/NullConstraintUsageAnalyzerTests.cs | Updates expectations and runtime tests around delegate evaluation / null-constraint behavior. |
| src/nunit.analyzers.tests/EqualToIncompatibleTypes/EqualToIncompatibleTypesAnalyzerTests.cs | Updates Func<T> expectation and adds tests for Func<double> and Func<Task<double>>. |
| src/nunit.analyzers.tests/Constants/NUnitFrameworkConstantsTests.cs | Ensures the new constants entry matches the referenced NUnit type. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Fixes #982
We need to consider their return type.
TestDelegate and Action are never evaluated for their return type as they don't have one.
The checks are not taking the NUnit version into account.
We could do that, but I was thinking to pre-warn users of
Func<T>being evaluated in future.