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

Support #[ignore] attribute in defmt_test #618

Merged
merged 15 commits into from
Nov 9, 2021

Conversation

justahero
Copy link
Contributor

@justahero justahero commented Oct 21, 2021

This PR adds support for the #[ignore] attribute in defmt_test to solve #390. Similar to the ignore attribute, tests can be annotated with the attribute to ignore particular tests.

  • use trybuild crate to check multiple conditions with the proc macro

Note the message is different from the suggestion in #390 and should be revised accordingly if needed

@justahero justahero changed the title Add "ignore" macro attribute to defmt_test Support #[ignore] attribute to defmt_test Oct 21, 2021
@justahero justahero changed the title Support #[ignore] attribute to defmt_test Support #[ignore] attribute o defmt_test Oct 21, 2021
@justahero justahero changed the title Support #[ignore] attribute o defmt_test Support #[ignore] attribute in defmt_test Oct 21, 2021
@justahero justahero force-pushed the feature/ignore-proc-macro-attribute-defmt-test branch from 8d4ef1a to 3f84476 Compare October 21, 2021 10:41
@Urhengulas Urhengulas self-requested a review October 22, 2021 16:29
@Urhengulas Urhengulas self-assigned this Oct 22, 2021
Copy link
Member

@japaric japaric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation looks good to me. Thanks for adding the UI tests. Left some comments inline.

Note the message is different from the suggestion in #390 and should be revised accordingly if needed

I don't feel strongly about the wording that's used at the end. I think I wrote "ignored" (without ellipsis) in the issue description because skipping tests is instantaneous, whereas running tests can take a while if the target needs to e.g. sample temperature once per seconds for a few seconds to check some requirement so one may see "running .." (long pause) and then new test.

firmware/defmt-test/macros/src/lib.rs Outdated Show resolved Hide resolved
@@ -0,0 +1,13 @@
error[E0658]: non-inline modules in proc macro input are unstable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(interesting that you also get an error from rustc about stability)

firmware/qemu/tests/defmt-test.rs Outdated Show resolved Hide resolved
@Urhengulas Urhengulas removed their assignment Oct 26, 2021
@Urhengulas Urhengulas removed their request for review October 26, 2021 12:59
@@ -69,6 +69,13 @@ mod tests {
Err(())
}

#[test]
#[ignore]
#[allow(dead_code)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, to clarify: I meant putting the allow in the expansion (proc-macro code) not in the input code. the semantics here should be following (this can be UI tested)

#[test]
#[ignore]
fn f() { // <- warning about `f` being `dead_code` MUST NOT be emitted
    let x = 42; // <- `dead_code` warning MUST be emitted here
}

I think it would be good to also test that compiler errors in ignored tests are emitted.
The expect semantic is that ignored tests are compiled but not executed.
A UI test like this can test that:

#[test]
#[ignore]
fn f() {
    let x: () = 42; //~ ERROR: type mismatch
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dead_code warning of an ignored function is handled by a recent change.

Unfortunately it's not easy to set up the suggested tests in the defmt-test crate using trybuild. The defmt-test crate is used as a library in a non-std environment, for example when set up from the app-template repo. I tried to add ui tests using trybuild but this works in std envs only.

@justahero justahero force-pushed the feature/ignore-proc-macro-attribute-defmt-test branch from 49b82a6 to 6914abd Compare November 8, 2021 11:04
Copy link
Member

@japaric japaric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spotted 2 issues

@justahero justahero force-pushed the feature/ignore-proc-macro-attribute-defmt-test branch from abd28ff to 918aa99 Compare November 8, 2021 17:22
Copy link
Member

@japaric japaric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

@japaric
Copy link
Member

japaric commented Nov 9, 2021

bors r+

@bors
Copy link
Contributor

bors bot commented Nov 9, 2021

Build succeeded:

@bors bors bot merged commit 34312b9 into main Nov 9, 2021
@bors bors bot deleted the feature/ignore-proc-macro-attribute-defmt-test branch November 9, 2021 09:41
#krate::export::check_outcome(#call, #should_error);
));
if ignore {
unit_test_calls.push(quote!(let _ = #call;));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will still call the test function if it has #[ignore] on it, leading to the issue reported in #731

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.

4 participants