Skip to content
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

Mismatch between compiler message and function arg position in tests #33

Closed
CuriousCorrelation opened this issue May 30, 2022 · 1 comment · Fixed by #34
Closed

Mismatch between compiler message and function arg position in tests #33

CuriousCorrelation opened this issue May 30, 2022 · 1 comment · Fixed by #34

Comments

@CuriousCorrelation
Copy link
Contributor

Message on failing a test with common::test_body(left, right) fn look like this:

---- proc_macro::different_fn_types::test_str stdout ----
thread '...' panicked at 'assertion failed: `(left == right)`
  left: `"Hi!"`,
 right: `"Hello!"`', tests/file...
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

which corrosponds to

common::test_body("Hello!", "Hi!").await;

The lhs/rhs mismatch between compiler's message and the function params is due to the underlying assert_eq! swap of expected and received args

pub async fn test_body(resp: ServiceResponse, expected_body: &str) {let body = test::read_body(resp).await;assert_eq!(expected_body, String::from_utf8(body.to_vec()).unwrap());
}

Swapping lhs and rhs

pub async fn test_body(resp: ServiceResponse, expected_body: &str) {let body = test::read_body(resp).await;assert_eq!(String::from_utf8(body.to_vec()).unwrap(), expected_body);
}

fixes this issue.

This follows The Rust Book convention of

assert_eq!(actual, expected);

I have a PR ready to go if this feels like a worthwhile issue and doesn't violate library wide chosen convention.

@DDtKey
Copy link
Owner

DDtKey commented May 30, 2022

Go ahead 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants