ActualValueDelegate and Func are always evaluated#984
ActualValueDelegate and Func are always evaluated#984manfred-brands merged 4 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.
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.
|
@mikkelbu Can you review this? Would be nice to get this in before NUnit 4.6 is out. |
|
Thanks for the ping @OsirisTerje - I've been so busy lately that I completely overlooked this PR. I'll see if I've time tonight. Alternatively, I should have time Friday evening. |
mikkelbu
left a comment
There was a problem hiding this comment.
I've not followed the discussion in NUnit about this, so I've just reviewed the changes without much context, but it looks good and I trust the judgement of @manfred-brands, so I'm happy to merge this when @manfred-brands is
(and then I'll make a release)
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.