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

Tests dont show up when using additional proc macro. #17011

Closed
t-moe opened this issue Apr 4, 2024 · 5 comments · Fixed by #17014
Closed

Tests dont show up when using additional proc macro. #17011

t-moe opened this issue Apr 4, 2024 · 5 comments · Fixed by #17014
Labels
C-support Category: support questions

Comments

@t-moe
Copy link

t-moe commented Apr 4, 2024

I have an integration test which looks as follows:

#![no_std]
#![no_main]

#[cfg(test)]
#[embedded_test::tests]
mod tests {
    #[test]
    fn test_a() {
        assert!(true)
    }

   #[test]
    fn test_b() {
        assert!(false)
    }
}

With the line #[embedded_test::tests] in place, rust analyzer wont show "Run Tests | Debug".
As soon as I remove the line, it works as expected.

I'm the author of embedded-test.
Since this used to work before, I'm now unsure whether this broke because of a change on my side (embedded-test lib) or a recent change in rust anaylzer. To me it looks like this is due to a recent change in rust-analyzer since the buttons also disappear when using the macro provided by defmt-test

Can you point me to the relevant parts of the rust analyzer source code (that decides whether it is a test or not) ?
EDIT: probably https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide/src/runnables.rs ?

Thank you

rust-analyzer version: 0.3.1906-standalone
rustc 1.79.0-nightly (88c2f4f5f 2024-04-02)

@t-moe t-moe added the C-support Category: support questions label Apr 4, 2024
@Veykril
Copy link
Member

Veykril commented Apr 4, 2024

Ah, the tests macro (at least for defmt) expands to things that no longer contain #[test] attributes which is why this no longer shows, the heuristic for test like attributes doesn't hit that. Curios how running cargo test still invokes the exported custom main there 🤔

@t-moe
Copy link
Author

t-moe commented Apr 4, 2024

Curios how running cargo test still invokes the exported custom main there 🤔

The idea is that you set up a cargo runner (e.g. something like "probe-rs run"), which will download the elf file..
Furthermore you have to set harness=false for the test in your Cargo.toml.

After flashing, when the MCU boots, it will then call the exported main function and run the tests in order.

@t-moe
Copy link
Author

t-moe commented Apr 4, 2024

I'll try whether I can fix this on my end by emitting #[::core::prelude::v1::test] from my macro, similar to how tokio does it for their test macro.

@Veykril
Copy link
Member

Veykril commented Apr 4, 2024

That would be one way, but I'll try adding something that considers exported mains inside cfg(test) modules to be test functions, as that looks like a test for a custom runner

@t-moe
Copy link
Author

t-moe commented Apr 4, 2024

but I'll try adding something that considers exported mains inside cfg(test) modules to be test functions

That would be great. I'm a bit hesitant with emitting the #[test] attribute from my macro, since it will cause weird compiler errors when the user forgets to set harness=false.

@bors bors closed this as completed in f8a4553 Apr 4, 2024
lnicola pushed a commit to lnicola/rust that referenced this issue Apr 7, 2024
… r=Veykril

fix: Consider `exported_name="main"` functions in test modules as tests

Fixes rust-lang/rust-analyzer#17011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-support Category: support questions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants