-
Notifications
You must be signed in to change notification settings - Fork 219
pkg/matcher: isEmpty should fail for null or non-collections. #2340
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
Comments
<img src="https://avatars.githubusercontent.com/u/4865287?v=3" align="left" width="48" height="48"hspace="10"> Comment by lrhn Removed Type-Defect label. |
<img src="https://avatars.githubusercontent.com/u/17034?v=3" align="left" width="48" height="48"hspace="10"> Comment by kevmoo Added Community-Idea, Community-StarterBug labels. |
This comment was originally written by [email protected] I'd call this a defect because except(myCollection, isNot(isEmpty)) not failing for null references can hide nasty bugs. |
<img src="https://avatars.githubusercontent.com/u/17034?v=3" align="left" width="48" height="48"hspace="10"> Comment by kevmoo Fair. We can wrap up a new isNotEmpty up as the new feature – depending on how this lands. This would be an easy fix in pkg/matcher. Patches welcome. Removed Type-Enhancement label. |
<img src="https://avatars.githubusercontent.com/u/17034?v=3" align="left" width="48" height="48"hspace="10"> Comment by kevmoo Removed Pkg-Unittest label. |
<img src="https://avatars.githubusercontent.com/u/17034?v=3" align="left" width="48" height="48"hspace="10"> Comment by kevmoo Added Fixed label. |
Originally opened as dart-lang/sdk#21562
This issue was originally filed by [email protected]
As there is no isNotEmpty matcher, you are forced to use isNot(isEmpty). However, expect(null, isNot(isEmpty)) passes because isEmpty returns false for non-collections or null. So, likewise, any other non-collection object would also wrongly pass such an expect call.
My suggested solution would be for isEmpty to throw an exception for "wrong" types.
Alternatively, an isNotEmpty matcher could be added.
Thanks,
Andreas
The text was updated successfully, but these errors were encountered: