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

defmt-test: support the #[ignore] attribute & raise error on unknown attributes #381

Closed
japaric opened this issue Feb 10, 2021 · 4 comments
Labels
type: enhancement Enhancement or feature request

Comments

@japaric
Copy link
Member

japaric commented Feb 10, 2021

The standard test runner uses this attribute to ignore (omit running) a unit test. We implement the same functionality or, at least, error when an unknown attribute is used within defmt_test::tests because right now cargo test-ing this:

#[ignore]
#[test]
fn loopback() { /* .. */ }

does run the test marked as #[ignore]

@japaric
Copy link
Member Author

japaric commented Feb 10, 2021

I did cargo expand and it looks like we are discarding all the attributes that appear in the input code.

@japaric japaric added type: enhancement Enhancement or feature request type: bug Something isn't working labels Feb 10, 2021
@japaric
Copy link
Member Author

japaric commented Feb 10, 2021

This doesn't work either:

#[cfg(ignore)]
#[test]
fn loopback() { /* .. */ }

in the sense that the test is compiled and executed when --cfg ignore is not passed to rustc.

@jonas-schievink jonas-schievink self-assigned this Feb 10, 2021
bors bot added a commit that referenced this issue Feb 10, 2021
383: defmt-test: Modify attributes in place and handle #[cfg] r=japaric a=jonas-schievink

Closes (?) #381 (but doesn't add `#[ignore]` support)

This changes the defmt-test macro to retain the `ItemFn`s and selectively delete defmt-test-specific attributes from them. The result is that the code is now simpler and arbitrary Rust attributes can be attached to tests. Doing so with `#[ignore]` gives the expected "unused attribute" warning.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
@jonas-schievink
Copy link
Contributor

This now behaves as expected, do we want to close it, or leave it open to track #[ignore] support?

@jonas-schievink jonas-schievink removed their assignment Feb 11, 2021
@jonas-schievink jonas-schievink removed the type: bug Something isn't working label Feb 11, 2021
@japaric
Copy link
Member Author

japaric commented Feb 15, 2021

I'll open a new issue about the #[ignore] attribute.

@japaric japaric closed this as completed Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Enhancement or feature request
Projects
None yet
Development

No branches or pull requests

2 participants