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

How to use with test-case ? #18

Closed
pinage404 opened this issue Oct 2, 2021 · 1 comment
Closed

How to use with test-case ? #18

pinage404 opened this issue Oct 2, 2021 · 1 comment

Comments

@pinage404
Copy link

I use test-case

i tried to use test-env-log but i got the error

error[E0659]: test is ambiguous (glob import vs any other name from outer scope during import/macro resolution)

use test_case::test_case;
use test_env_log::test;

#[test_case(4,  2  ; "when operands are swapped")]
#[test_case(-2, -4 ; "when both operands are negative")]
#[test_case(2,  4  ; "when both operands are positive")]
fn multiplication_tests(x: i8, y: i8) {
	let actual = (x * y).abs();

	assert_eq!(8, actual)
}
cargo test
   Compiling git-gamble v2.1.1-alpha.0 (/home/pinage404/Project/git-gamble)
error[E0659]: `test` is ambiguous (glob import vs any other name from outer scope during import/macro resolution)
   --> tests/test_env_log_with_test_case.rs:4:1
    |
4   | #[test_case(4,  2  ; "when operands are swapped")]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ambiguous name
    |
note: `test` could refer to the attribute macro imported here
   --> tests/test_env_log_with_test_case.rs:4:1
    |
4   | #[test_case(4,  2  ; "when operands are swapped")]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: consider adding an explicit import of `test` to disambiguate
    = help: or use `self::test` to refer to this attribute macro unambiguously
note: `test` could also refer to the attribute macro defined here
   --> /media/exec_downloaded/rust/rustup/toolchains/1.55.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:119:13
    |
119 |     pub use super::v1::*;
    |             ^^^^^^^^^^^^
    = note: this error originates in the attribute macro `test_case` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0659`.
error: could not compile `git-gamble` due to previous error

How to use with test-case ?

@d-e-s-o
Copy link
Owner

d-e-s-o commented Oct 5, 2021

The issue exists because test-case is generating a super::* import and then Rust can't decide which test attribute to use, from the looks of it. If I adjust the test-case code as follows:

--- src/lib.rs
+++ src/lib.rs
@@ -386,8 +386,8 @@ fn render_test_cases(test_cases: &[TestCase], mut item: ItemFn) -> TokenStream {

     let output = quote! {
         mod #mod_name {
-            #[allow(unused_imports)]
-            use super::*;
+            //#[allow(unused_imports)]
+            //use super::*;

             #(#additional_usings)*

everything works fine. You will have to take that up with them.

In addition, what you are doing is not really how the crate is meant to be used with other attributes, as you can read here. Next time, I encourage you to do some research first.

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

2 participants