assert icon indicating copy to clipboard operation
assert copied to clipboard

Make`assert.Zero` harder to misuse

Open twpayne opened this issue 2 years ago • 3 comments

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?

twpayne avatar Mar 02 '23 22:03 twpayne

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 avatar Dec 31 '23 17:12 glesica

Oh, I guess this also ought to fix your case... https://github.com/alecthomas/assert/commit/929325d69bc1ce5d5c57cf1ccf58dc524d0557dc

glesica avatar Dec 31 '23 17:12 glesica

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 avatar Dec 31 '23 18:12 twpayne

Closing due to inactivity.

twpayne avatar May 20 '24 23:05 twpayne