testify icon indicating copy to clipboard operation
testify copied to clipboard

Deprecate ObjectsAreEqual and ObjectsAreEqualValues from the assert package and move them in a separate package for reuse

Open nikolavp opened this issue 2 years ago • 2 comments

The two methods are currently located in the assert package making them easily mistaken as "assert" methods when in fact they only return a boolean which indicates if the objects are equal or equal values.

There is lots and lots of code that incorrectly assumes that these methods are asserting equality.

Although it is clear from their signature (they don't accept a testing.T object), one assumes that everything in the assert package is asserting something about the arguments.

Can we move these in a separate package called something like equal and deprecate the instances in assert so at least people don't make the mistake again.

nikolavp avatar Apr 21 '22 13:04 nikolavp

Just had a long discussion about this at work, and realised that this has caught quite a few of us out multiple times, so I'm in complete agreement that this should be moved to a seperate package that makes their intended use clear.

mminklet avatar Oct 07 '22 05:10 mminklet

Created a PR for this https://github.com/stretchr/testify/pull/1279

mminklet avatar Oct 10 '22 02:10 mminklet

I was bit by this today, I'm new to Go and getting my feet wet with testing and kept scratching my head why this method wasn't failing even when I passed in an obviously incorrect comparison object.

Looks like the PR is stuck in review limbo, hopefully this gets resolved soon.

k3n avatar Mar 27 '23 17:03 k3n