I have definitely seen (and probably written) test code that puts the expected value on both the left and the right, so ascribing a meaning to the positions now would make a lot of existing code wrong.
Yeah, I think this would be a breaking change. Your only realistic hope is to write your own assertion macro that changes the message to what you want.
A problem with that is that which side is the actual value and which side is the expected value is completely arbitrary. In fact I think I have code bases that, while each internally consistent on this point, disagree with each other w.r.t. convention.
assert_eq! should output both the stringized versions of the parameters and their values, IMO, which would also in most cases make clear which one is the expected one, in addition to providing more information without having to delve into the code.
With x.should().equal(2), it's very clear which is the expected, in a way where I'd say "oh, yeah, that PR to fix the order makes it obviously better", which isn't the case for the symmetric macro.
I have definitely seen (and probably written) test code that puts the expected value on both the left and the right, so ascribing a meaning to the positions now would make a lot of existing code wrong.
It'd also make the code lot less messy. Imagine it was Tuesday and raining, so one developer put the expected value at the left, while on a sunny Friday, another dev put it on the right in the same test class.
A problem with that is that which side is the actual value and which side is the expected value is completely arbitrary.
Right, but there's nothing wrong in adopting a convention. JUnit Assert, for example, puts expected on the left.
x.should().equal(2) , it's very clear which is the expected
Agreed that'll be better, but the question is, do you want to do nothing and perpetuate the confusion, or do something that helps, even though a little.
There isn't any confusion. Right now, if you said left was expected and right was actual you'd have A LOT of code that would be backwards of that and that WOULD be confusing. Not just tests. The right way to disambiguate (if needed) is to use the optional message as I previously mentioned.
The compiler can't enforce that the expected value is always placed in one position and the actual value in the other. This is a classic "gotcha" across many other languages and testing frameworks.
I'm not convinced there's too much of a problem here in the first place: Most of the times, even if you knew which one of the value was the expected, you'd still need to look into the code (at the point kindly pointed out by the error message) in order to understand the necessaryt context, i. e. what the assertion even means in the first place. Once you look at the code, it's typically trivial to understand which of the values was the expected one. Arguably it would be more confusing and harder to relate the error message to the code if the error message didn't clearly specify which one of the values is from the left expression and which one from the right one.
In order to even have a chance of, sometimes, being able to skip looking into the code, the error message would probably — at least — also have to specify what the expressions look like that were being evaluated. (And once you see the expressions, you might often already know which value was the expected one.)
Agreed. My personal experience is that "expected X, got Y" messages don't help me at all, and I usually still need to look at the test code to figure out what was the semantic.
The exception to this in my experience is when the output is presented in diff form. This often provides enough context as well, but requires formatting and is mostly applicable to response style tests, although I find it useful elsewhere. (it also does not belong in std)