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

Empty/NotEmpty return confusing results for custom types with underlying type string #469

Closed
bits01 opened this issue Jul 5, 2017 · 2 comments

Comments

@bits01
Copy link
Contributor

bits01 commented Jul 5, 2017

Consider the following example:

type key string

func TestEmpty(t *testing.T) {
	var k key = ""
	assert.Empty(t, k, "confusing to fail")
	assert.NotEmpty(t, k, "this is very error prone when used in tests")
}

The assert.Empty above fails. While I understand what is going on, it is confusing and very error prone in tests when one uses assert.NotEmpty instead.

bits01 added a commit to bits01/testify that referenced this issue Jul 5, 2017
reflect.Value.Len() can cover more types, per godoc:
> Len returns v's length. It panics if v's Kind is not Array, Chan, Map, Slice, or String.
@bits01
Copy link
Contributor Author

bits01 commented Jul 5, 2017

Please take a look at PR #470.

reflect.Value.Len() can cover more types, per godoc:
https://golang.org/pkg/reflect/#Value.Len

Len returns v's length. It panics if v's Kind is not Array, Chan, Map, Slice, or String.

DAddYE pushed a commit that referenced this issue Aug 9, 2017
reflect.Value.Len() can cover more types, per godoc:
> Len returns v's length. It panics if v's Kind is not Array, Chan, Map, Slice, or String.
@bits01
Copy link
Contributor Author

bits01 commented Aug 9, 2017

PR #470 merged. Thank you.

@bits01 bits01 closed this as completed Aug 9, 2017
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