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

Makeassert.Zero harder to misuse #12

Closed
twpayne opened this issue Mar 2, 2023 · 4 comments
Closed

Makeassert.Zero harder to misuse #12

twpayne opened this issue Mar 2, 2023 · 4 comments

Comments

@twpayne
Copy link

twpayne commented Mar 2, 2023

Firstly, thank you for this excellent library! I'm slowly migrating my projects from stretchr/testify to alecthomas/assert.

What's wrong with this code?

    assert.Zero(t, 0, len(foo), "foo should have length zero")

Spoiler alert: this test always passes, no matter how big len(foo) is.

Is there a way to make this API harder to misuse?

@glesica
Copy link

glesica commented Dec 31, 2023

Aren't you calling it wrong, though? There's no expected value for that function, it's assumed to be whatever the zero value is for the type. Or do you mean that it's easy to accidentally call incorrectly and then end up with a test that always passes?

@glesica
Copy link

glesica commented Dec 31, 2023

Oh, I guess this also ought to fix your case... 929325d

@twpayne
Copy link
Author

twpayne commented Dec 31, 2023

Or do you mean that it's easy to accidentally call incorrectly and then end up with a test that always passes?

Exactly. Your fix looks great, thank you!

@twpayne
Copy link
Author

twpayne commented May 20, 2024

Closing due to inactivity.

@twpayne twpayne closed this as completed May 20, 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

2 participants