Skip to content

ActualValueDelegate and Func are always evaluated#984

Merged
manfred-brands merged 4 commits intonunit:masterfrom
manfred-brands:Issue982_RecognizeFunc
May 2, 2026
Merged

ActualValueDelegate and Func are always evaluated#984
manfred-brands merged 4 commits intonunit:masterfrom
manfred-brands:Issue982_RecognizeFunc

Conversation

@manfred-brands
Copy link
Copy Markdown
Member

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.

We need to consider their return type.
TestDelegate and Action are never evaluated for their return type as they don't have one.
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

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.UnwrapActualType to unwrap System.Func<T> (and introduced handling for AsyncTestDelegate).
  • Added AsyncTestDelegate to the framework constants (and corresponding constants test).
  • Updated/added analyzer tests to reflect Func<T> unwrapping behavior (including new Func<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.

Comment thread src/nunit.analyzers/Helpers/AssertHelper.cs
Comment thread src/nunit.analyzers.tests/NullConstraintUsage/NullConstraintUsageAnalyzerTests.cs Outdated
@OsirisTerje
Copy link
Copy Markdown
Member

@mikkelbu Can you review this? Would be nice to get this in before NUnit 4.6 is out.

@mikkelbu
Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member

@mikkelbu mikkelbu left a comment

Choose a reason for hiding this comment

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

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)

@mikkelbu mikkelbu added this to the Release 4.13 milestone May 1, 2026
@manfred-brands manfred-brands merged commit cf8887f into nunit:master May 2, 2026
6 checks passed
@manfred-brands manfred-brands deleted the Issue982_RecognizeFunc branch May 2, 2026 08:23
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.

Recognized Func<T> return values

4 participants