Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Is.EqualTo(default) with Is.Default #828

Open
manfred-brands opened this issue Jan 9, 2025 · 0 comments
Open

Replace Is.EqualTo(default) with Is.Default #828

manfred-brands opened this issue Jan 9, 2025 · 0 comments
Assignees

Comments

@manfred-brands
Copy link
Member

With new overloads to EqualTo in 4.3.0 we can no longer uniquely determine default.
But even in older cases, default would always mean default(object) which would be null.
This is likely not the intention of the caller when they use:

Assert.That(false, Is.EqualTo(default));`

As this compares a boolean with null which always fails:

Assert.That(true, Is.EqualTo(default))
  Expected: null
  But was:  True
Assert.That(false, Is.EqualTo(default))
  Expected: null
  But was:  False

Add a rule that warns about Is.EqualTo(default) and convert this to Is.Default for NUnit 4.
For NUnit 3 we could translate:

Assert.That<TActual>(actual, Is.EqualTo(default));

with:

Assert.That<TActual>(actual, Is.EqualTo(default(TActual));
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

No branches or pull requests

2 participants