Skip to content

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

Closed
DartBot opened this issue Jun 5, 2015 · 6 comments
Closed

pkg/matcher: isEmpty should fail for null or non-collections. #2340

DartBot opened this issue Jun 5, 2015 · 6 comments
Labels
contributions-welcome Contributions welcome to help resolve this (the resolution is expected to be clear from the issue) package:matcher type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@DartBot
Copy link

DartBot commented Jun 5, 2015

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

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<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.
Added Type-Enhancement, Area-Pkg, Pkg-Unittest, Triaged labels.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<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.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

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.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<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.
Added Type-Defect label.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<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.
Added Pkg-matcher label.

@DartBot DartBot added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Jun 5, 2015
@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/17034?v=3" align="left" width="48" height="48"hspace="10"> Comment by kevmoo


dart-archive/matcher@755ee44


Added Fixed label.

@DartBot DartBot added the contributions-welcome Contributions welcome to help resolve this (the resolution is expected to be clear from the issue) label Jun 6, 2015
@mosuem mosuem transferred this issue from dart-archive/matcher Oct 18, 2024
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributions-welcome Contributions welcome to help resolve this (the resolution is expected to be clear from the issue) package:matcher type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants