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

Use fully qualified #[test] attribute path #105

Merged

Conversation

alanbriolat
Copy link
Contributor

I found that uses of #[test_case] fail to build when a different procedural macro attribute is imported with the name test. For example, the simple test code:

#[cfg(test)]
mod tests {
    use test_case::test_case;
    use test_log::test;

    #[test_case("hello, world")]
    fn test_something(s: &str) {
        assert_eq!(s, "hello, world");
    }
}

results in the build error:

error[E0659]: `test` is ambiguous
   --> (REDACTED)
    |
265 |     #[test_case("hello, world")]
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ambiguous name
    |
    = note: ambiguous because of a conflict between a name from a glob import and an outer scope during import or macro resolution
note: `test` could refer to the attribute macro imported here
   --> (REDACTED)
    |
265 |     #[test_case("hello, world")]
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = 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
   --> /home/alan/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:129:13
    |
129 |     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)

I don't expect test_case to necessarily wrap another test helper, but this import probably shouldn't break it. I looked at a couple of other test attributes (#[test_log::test] and #[tokio::test]) to confirm they use #[::core::prelude::v1::test] instead of #[test] in their generated code to avoid ambiguity, so I think the same approach should probably be applied to #[test_case].

@luke-biel
Copy link
Collaborator

luke-biel commented Sep 27, 2022

Thank you for the contribution :) This is something we definitely overlooked.

It appears that once_cell updated their MSRV. I'm gonna fix master and then notify you that you can rebase.

@luke-biel
Copy link
Collaborator

Ok @alanbriolat, CI passes, so all I ask from you is to merge in our master into your changes, it should all pass then and we can finalize this PR :)
Thanks again for contribution

There is no guarantee that #[test] means #[::core::prelude::v1::test],
because some other helpers (e.g. `test-log`) encourage shadowing that
attribute name for simplicity. Other test helpers (e.g. `test-log`,
`tokio-macros`) avoid ambiguity by using the full attribute path.
@luke-biel luke-biel merged commit 2c05a1b into frondeus:master Sep 29, 2022
@luke-biel
Copy link
Collaborator

Thank you very much, I'll try to release it asap

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 this pull request may close these issues.

None yet

2 participants