-
Notifications
You must be signed in to change notification settings - Fork 18
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
Snapbox parameter order (expected, actual) breaks common convention #226
Comments
For |
I've never seen frameworks using (expected, actual) but I don't doubt that they exist. Haha ... this is also the first time for me hearing about "yoda conditions" ... Wikipedia even has an article about them.
That is very understandable. Since snapbox using (actual, expected) is somewhat unexpected, I think this would deserve a section in the root module doc comment. If you expect that you're not getting to address this issue in the near future (which is also very understandable), I'd be happy to make a PR to add such a documentation section. Let me know if you'd like such a PR. |
... I think the reason might have been to align with |
Yes for a function called "diff" I'd agree that (old, new) makes much more sense than (new, old). However the function is called "assert" and as I explained the common convention for assert statements is putting actual before expected. |
Out of curiosity, are there any Rust libraries that do this? I mean, although this might be the correct way, the breaking change is not compelling to make, imagine you wake up tomorrow and your function is inverted. |
This leaves us room to evaluate assert-rs#223 Fixes assert-rs#226
This leaves us room to evaluate assert-rs#223 Fixes assert-rs#226
#296 was pulled out of The first is what the signature for pub fn try_eq(
&self,
expected: crate::Data,
actual: crate::Data,
actual_name: Option<&dyn std::fmt::Display>,
) -> Result<()> { should be likely pub fn try_eq(
&self,
actual_name: Option<&dyn std::fmt::Display>,
actual: crate::Data,
expected: crate::Data,
) -> Result<()> { Then in talking over the above with @Muscraft that led to "why is there a preference for one over the other" and this got me looking at prior art
|
With the new `eq_` variants (to not break compatibility), we switched param order as part of the path to assert-rs#226 Cherry pick 1762764 (assert-rs#291)
With the new `eq_` variants (to not break compatibility), we switched param order as part of the path to assert-rs#226 Cherry pick 1762764 (assert-rs#291)
This leaves us room to evaluate assert-rs#223 Fixes assert-rs#226 Cherry pick 2a1a25f (assert-rs#296)
The following code:
results in:
which funnily enough is rather unexpected. When writing comparisons in code it is common practice to put constants on the right side of the operator e.g:
rather than:
And even though
std::assert_eq
does not document any convention and also just speaks ofleft
andright
in its panic messages, the vast majority of Rust code uses the same convention of putting the expected value last (e.g.assert_eq!(self.length, 0)
instead ofassert_eq!(0, self.length)
.The non-file-based methods of snapbox however use the opposite order ... which matters because snapbox (contrary to std, pretty_assertions and similar-asserts does label its diff with expected/actual instead of just left/right).
Note that I think attempting to label actual/expected for non-file based methods is a good idea ... it's just that I think not breaking the user expectation is more important than anything else. We could still achieve both labeling and adhering to user expectations but it would require a breaking change.
The text was updated successfully, but these errors were encountered: