Skip to content

ActualValueDelegate and Func are always evaluated#984

Open
manfred-brands wants to merge 3 commits intonunit:masterfrom
manfred-brands:Issue982_RecognizeFunc
Open

ActualValueDelegate and Func are always evaluated#984
manfred-brands wants to merge 3 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
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

2 participants