testify icon indicating copy to clipboard operation
testify copied to clipboard

Implements arg order is backwards

Open willfaught opened this issue 10 years ago • 13 comments

Most non-expected-actual functions, like EqualError and Len, put the object to be examined first and the expected value second, but Implements does it in reverse order: type first, then object. This makes it hard to remember.

willfaught avatar Mar 19 '15 17:03 willfaught

Please fix this and submit a PR. It would be great if it were consistent.

On 19 Mar 2015, at 17:16, Will Faught [email protected] wrote:

Most non-expected-actual functions, like EqualError and Len, put the object to be examined first and the expected value second, but Implements does it in reverse order: type first, then object. This makes it hard to remember.

— Reply to this email directly or view it on GitHub https://github.com/stretchr/testify/issues/146.

matryer avatar Mar 19 '15 21:03 matryer

I would argue that Implements is correct, and Len is backwards. In most of the functions, the thing being tested against is the second argument, and the thing being tested is the third (and latter) argument(s). Thus in Len, the expected value should be the second argument.

Functions I think need to be fixed: Contains, Len, HTTPBodyContains, HTTPBodyNotContains, NotContains

phemmer avatar Jul 01 '15 14:07 phemmer

Agreed.

willfaught avatar Jul 01 '15 15:07 willfaught

Looks like another backwards method has been added since this issue was created: EqualError

phemmer avatar Feb 11 '17 22:02 phemmer

I believe this issue and related PR can move forward again, but we need to take a look at #399 which makes a fair point.

mvdkleijn avatar Apr 07 '20 14:04 mvdkleijn

I agree with https://github.com/stretchr/testify/issues/399, actually. Go has a strong preference for the actual-then-expected order of comparison values. This ticket is just about the order—whatever it may be—being consistent among the funcs.

willfaught avatar Apr 10 '20 07:04 willfaught

Closing due to no activity.

willfaught avatar Nov 19 '22 02:11 willfaught

request to reopen this for v2, the v1 parameter ordering is very counter intuitive

zzh8829 avatar Jun 14 '23 19:06 zzh8829

+1 - Len is inconsistent. The asserted value comes last, vs EqualValues which comes first. In general, a bunch of these are inconsistent and it's pretty frustrating.

tonyhb avatar Jan 30 '24 13:01 tonyhb

As this is seems to be the oldest one, and it's already in the v2.0.0 milestone, sure. If v2 ever happens the expected/actual order will be made consistent. Most likely using the order from assert.Equal as it's the most ubiquitous.

brackendawson avatar Feb 01 '24 00:02 brackendawson

In regards to the naming convention, I vote for renaming the sides to "left" and "right" like they are called in Rust, eliminating the discrepancy between all the functions and making the sides unambiguous no matter which standard you're used to (expected-actual/actual-expected).

Thoughts? @willfaught @brackendawson

HeCorr avatar Aug 14 '24 09:08 HeCorr

That’s what I’ve done in my own test helper. Given the age of this issue, I doubt this will ever happen to testify. Better to make your own, better library.

willfaught avatar Aug 14 '24 19:08 willfaught