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

Reexamine how Nimble treats nils in Swift code. #1124

Open
younata opened this issue Feb 27, 2024 · 0 comments
Open

Reexamine how Nimble treats nils in Swift code. #1124

younata opened this issue Feb 27, 2024 · 0 comments
Milestone

Comments

@younata
Copy link
Member

younata commented Feb 27, 2024

This comes out of #1123 (thanks @jeslyvarghese!), which is specifically caused by... essentially confusion as to what should be the correct behavior of the equal matcher with regards to nil. See my comment here for more context.

Essentially, I think that we should fundamentally reexamine how nils are treated in Nimble. For example, the equal matcher should properly operate on nil. expect(nil as Int?).toNot(equal(0)) should pass, because nil is not equal to 0. expect(nil).to(equal(nil)) should also pass, because nil is equal to nil. We should do the same for a bunch of the other built-in matchers in Nimble.

Matchers to update:

  • equal
  • TBD.

Additionally, though, we should also take the opportunity to reexamine how Optionals are handled internally. I think that Matchers should be able to declare in the type system that they don't handle Optionals, and Nimble will fail the matcher if it receives nil. No more guard let value = try actualExpression.evaluate() else { return MatcherResult(.fail, message.appendedBeNilHint()) }. That should either be a runtime test failure, or even a compiler failure.

While we're at it, maybe also change how Expressions are handled? So that Optionality can be passed with them (right now, Expression/AsyncExpression essentially wrap () -> T?, regardless of whether T is an Optional<SomethingElse> or something else). In other words, passing a non-optional expression into expect or require should be a thing. This change feels a bit more radical, though.

Regardless, we should keep the current behavior when used with Objective-C, thanks to the fact that Objective-C doesn't have the concept of non-optional objects. This will require special-casing, but I think it'll be worth it.

@younata younata added this to the v14.0.0 milestone Feb 27, 2024
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

1 participant