-
Notifications
You must be signed in to change notification settings - Fork 8
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
zero: use zero instead of asserr.Equal(t, 0, v)
#75
Comments
I've read the consideration about the doubt about using Zero vs Empty
I'll explain in this issue what I plan to implement, so we could talk about the implementation here |
I created the issue to keep a track of it, and allow other people to discuss it. Stay tuned, and ping me if you see no progress in the next month. |
I agree with you @Antonboom the use case I will check a bit further in the code of testify, but I think is what we should look for https://github.com/stretchr/testify/blob/master/assert/assertions_test.go#L23-L85 I would say
And same for Everything other types that |
For this reason, and because I struggle in making it works with |
@ccoVeille hi I reread carefully the messages and examples above and looks like I was wrong
And these are separate checkers, and zeros = []interface{}{
false,
byte(0),
complex64(0),
complex128(0),
float32(0),
float64(0),
int(0),
int8(0),
int16(0),
int32(0),
int64(0),
rune(0),
uint(0),
uint8(0),
uint16(0),
uint32(0),
uint64(0),
uintptr(0),
"",
[0]interface{}{},
[]interface{}(nil),
struct{ x int }{},
(*interface{})(nil),
(func())(nil),
nil,
interface{}(nil),
map[interface{}]interface{}(nil),
(chan interface{})(nil),
(<-chan interface{})(nil),
(chan<- interface{})(nil),
} If user uses Also need to grep some statistics and understand the history of creation of |
Thanks for digging further into the checks. There are definitely testify assert that covers the same kind of check. I mean an Your tool is there to suggest using the right asserted. So I think while each checker COULD handle them all, BUT your tool will have to provide opinionated suggestions, and document them. For me, using Considering a string is a list of character, you can often find people using So here is the same, Empty and Zero have lot in common, you will have to define what is the best for each type. Let's continue the discussion |
Also, as I previously said, I think empty and zero could be handled in the same checker, as they are very close. |
I think the project would need something like this: Nil is suggested for
NoError is suggested for
Empty is suggested for
Zero is suggested for
This list has to be completed, and discussed of course. I let out all the compare operators and co. My approach is the opposite of "this checker does that". It's more a "what is expected from testifylint". I'm not talking about how it's implemented, but what would be the good way to use testify. So, a guidance, it would be opinionated. It could be used as a reference for new checkers implementation. I could write a design note in a markdown file you could review. EDIT: 2024-05-28 Zero was completed with "zero time" use cases |
You didn't reply to my suggestion and questions. It's OK. But I'm busy IRL for a while. Could you please unassign me from the issue? Thanks |
Hi @dolmen I'm curious about your thoughts about this. Thanks |
@dolmen didn't reply and it's OK, he might be busy Maybe, I should bring the discussion on https://gophers.slack.com/archives/C18A3680H I also thought about opening a discussion on https://github.com/stretchr/testify/discussions It would require me to work on the matrix I talked about #75 (comment) before opening the discussion of course what do you think @Antonboom ? |
time.Time has a https://pkg.go.dev/time#Time.IsZero function. How do you recommend checking a time.Time is zero ? using assert.True(t, time.Time.IsZero()) or assert.Zero(t, time.Time) ? |
Good remark, I will have to check what it does, but I would say but I have to check if it works first |
Just noticed @dolmen added a 👍 to #75 (comment) so I would say, we had a kind of approval 😄 |
thanks @mmorel-35 for your feedback and your interest in the discussion I brought |
confirmed it works perfectly https://go.dev/play/p/LjKyrg0sn1H So I would recommend using assert.Zero for checking zero time thanks for your suggestion @mmorel-35 I edited #75 (comment) |
@ccoVeille , |
The project is somehow abandoned, but it could be a good source of inspiration |
@mmorel-35 do you think you could use the zero project to work on populating the document I started writing? Do you agree with me that having such a table out of current checker consideration would be a good thing? I'm busy with my new born kid 👨👩👧👧, I'm pretty active on GitHub but I'm mostly using my phone. Most of my time is spent I'm trying to make my baby girl sleep 😪 any help would be appreciated. |
@mmorel-35 by being suggested you meant here? |
@mmorel-35 I'm curious how
|
It seems to be close to what you started to identify. There probably be some differences of course
It's probably easier to have inside the project but probably isolated so it can be outside in a second time
Good luck with your child. I won't be able to help on the development part. I wanted to share what I found that could help the good improvements testifylint is providing .
Exactly here, yes |
asserr.Equal(t, 0, v)
I don't see the benefits from wasting resources on support matrix above. And we have a lot of more useful checkers (see issues list), that protect from real bugs and not just stylish thing. Thanks! |
For records, I started working on the implementation of this feature request.
https://github.com/Antonboom/testifylint/blob/master/CONTRIBUTING.md#zero
The text was updated successfully, but these errors were encountered: