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

Is it possible to use with pretty_assertions? #38

Closed
autoferrit opened this issue Feb 5, 2020 · 3 comments
Closed

Is it possible to use with pretty_assertions? #38

autoferrit opened this issue Feb 5, 2020 · 3 comments

Comments

@autoferrit
Copy link

autoferrit commented Feb 5, 2020

I have been playing with pretty_assertions and really like it. But when trying to use it with test-case I seem to get errors of ambiguity over assert_eq. Is it possible to use these two together?

error[E0659]: `assert_eq` is ambiguous (glob import vs any other name from outer scope during import/macro resolution)
 --> src\squared\tests.rs:7:1
  |
7 | #[test_case(5 => 25 ; "should be 25")]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ambiguous name
  |
  = note: `assert_eq` could refer to a macro from prelude
note: `assert_eq` could also refer to the macro imported here
 --> src\squared\tests.rs:7:1
  |
7 | #[test_case(5 => 25 ; "should be 25")]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: consider adding an explicit import of `assert_eq` to disambiguate
  = help: or use `self::assert_eq` to refer to this macro unambiguously

warning: unused import: `test_case::test_case`
 --> src\guessing_game\tests.rs:3:5
  |
3 | use test_case::test_case;
  |     ^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

Here is the code. Uncommenting the pretty_assertions line gives the error above. Without it, it runs normally.

#[allow(unused_imports)]
use crate::squared::squared;
//use pretty_assertions::assert_eq;
#[cfg(test)]
use test_case::test_case;

#[test_case(5 => 25 ; "should be 25")]
#[test_case(2 => 4 ; "should be 4")]
fn squared_test(num: i32) -> i32 {
    squared(num)
@luke-biel
Copy link
Collaborator

luke-biel commented Feb 5, 2020

This looks like #31

for now, what can be used is:

#[test_case(2, 4 ; "should be 4")]
fn squared_test(num: i32, expected: i32) {
    let actual = squared(num)
    pretty_assertions::assert_eq!(expected, actual)
}

@frondeus
Copy link
Owner

frondeus commented Feb 5, 2020

At least right now I think we should use explicitly use std::macros::assert_eq! in test_case to avoid unambiguous cases.
But yes, it's related to #31

@autoferrit
Copy link
Author

Yea, I thought that could be related but wasn't sure how. That seemed much more in depth to what the library needed where here I am mainly looking for a sort of workaround for now.

This solution above should be easy enough as it can largely be updated by a couple find & replaces uses. thanks.

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

No branches or pull requests

3 participants