-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ce651d4
Add ignore flag to Test struct
justahero 8937ebd
Use dummy statement for ignored tests
justahero 53df11e
Use trybuild to test macro code generation
justahero a306961
Fix lint warning in test harness
justahero 881965a
Fix snapshot test
justahero b6f4cdd
Apply review feedback
justahero cb4c156
Add test to check init's return type in test
justahero 5b4591b
Add test to check function signature matches init return type
justahero 816223b
Mark ignored functions as used in defmt-test
justahero a73bc9e
Fix lint warning
justahero 0918850
Test cargo workspace with additional 'alloc' feature
justahero f15cb48
Add xtask test to run ui tests
justahero 918aa99
Add CI job to run all ui tests
justahero 2ae19b9
Fix working dir of test-ui xtask command1
justahero 7e6d622
Add main function to UI test
justahero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#[test] | ||
fn ui() { | ||
let t = trybuild::TestCases::new(); | ||
t.compile_fail("tests/ui/*.rs"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
fn main() {} | ||
|
||
#[defmt_test_macros::tests] | ||
mod tests { | ||
#[init] | ||
fn first() {} | ||
|
||
#[init] | ||
fn second() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: only a single `#[init]` function can be defined | ||
--> tests/ui/init-duplicate.rs:9:8 | ||
| | ||
9 | fn second() {} | ||
| ^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
fn main() {} | ||
|
||
#[defmt_test_macros::tests] | ||
mod tests { | ||
#[init] | ||
#[ignore] | ||
fn init() {} | ||
} |
5 changes: 5 additions & 0 deletions
5
firmware/defmt-test/macros/tests/ui/init-has-ignore-macro.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: `#[ignore]` is not allowed on the `#[init]` function | ||
--> tests/ui/init-has-ignore-macro.rs:7:8 | ||
| | ||
7 | fn init() {} | ||
| ^^^^ |
9 changes: 9 additions & 0 deletions
9
firmware/defmt-test/macros/tests/ui/init-has-invalid-function-signaturen.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
fn main() {} | ||
|
||
#[defmt_test_macros::tests] | ||
mod tests { | ||
#[init] | ||
fn hello(a: i32, b: i32) -> i32 { | ||
a + b | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
firmware/defmt-test/macros/tests/ui/init-has-invalid-function-signaturen.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: `#[init]` function must have signature `fn() [-> Type]` (the return type is optional) | ||
--> tests/ui/init-has-invalid-function-signaturen.rs:6:8 | ||
| | ||
6 | fn hello(a: i32, b: i32) -> i32 { | ||
| ^^^^^ |
8 changes: 8 additions & 0 deletions
8
firmware/defmt-test/macros/tests/ui/init-has-should-error-macro.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
fn main() {} | ||
|
||
#[defmt_test_macros::tests] | ||
mod tests { | ||
#[init] | ||
#[should_error] | ||
fn init() {} | ||
} |
5 changes: 5 additions & 0 deletions
5
firmware/defmt-test/macros/tests/ui/init-has-should-error-macro.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: `#[should_error]` is not allowed on the `#[init]` function | ||
--> tests/ui/init-has-should-error-macro.rs:7:8 | ||
| | ||
7 | fn init() {} | ||
| ^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fn main() {} | ||
|
||
#[defmt_test_macros::tests] | ||
mod tests; |
13 changes: 13 additions & 0 deletions
13
firmware/defmt-test/macros/tests/ui/mod-must-be-inline.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error[E0658]: non-inline modules in proc macro input are unstable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (interesting that you also get an error from rustc about stability) |
||
--> tests/ui/mod-must-be-inline.rs:4:1 | ||
| | ||
4 | mod tests; | ||
| ^^^^^^^^^^ | ||
| | ||
= note: see issue #54727 <https://github.com/rust-lang/rust/issues/54727> for more information | ||
|
||
error: module must be inline (e.g. `mod foo {}`) | ||
--> tests/ui/mod-must-be-inline.rs:4:1 | ||
| | ||
4 | mod tests; | ||
| ^^^ |
9 changes: 9 additions & 0 deletions
9
firmware/defmt-test/macros/tests/ui/test-has-immutable-param.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
fn main() {} | ||
|
||
#[defmt_test_macros::tests] | ||
mod tests { | ||
#[test] | ||
fn say(name: &str) { | ||
justahero marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert_eq!("name", name); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
firmware/defmt-test/macros/tests/ui/test-has-immutable-param.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: parameter must be a mutable reference (`&mut $Type`) | ||
--> tests/ui/test-has-immutable-param.rs:6:12 | ||
| | ||
6 | fn say(name: &str) { | ||
| ^^^^ |
14 changes: 14 additions & 0 deletions
14
firmware/defmt-test/macros/tests/ui/test-has-incompatible-init-signature.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
fn main() {} | ||
|
||
#[defmt_test_macros::tests] | ||
mod tests { | ||
#[init] | ||
fn init() -> u32 { | ||
0_u32 | ||
} | ||
|
||
#[test] | ||
fn say(value: &mut u16) { | ||
assert!(true); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
firmware/defmt-test/macros/tests/ui/test-has-incompatible-init-signature.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: this type must match `#[init]`s return type | ||
--> tests/ui/test-has-incompatible-init-signature.rs:11:24 | ||
| | ||
11 | fn say(value: &mut u16) { | ||
| ^^^ |
9 changes: 9 additions & 0 deletions
9
firmware/defmt-test/macros/tests/ui/test-has-invalid-function-signature.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
fn main() {} | ||
|
||
#[defmt_test_macros::tests] | ||
mod tests { | ||
#[test] | ||
fn hello(a: i32, b: i32) -> i32 { | ||
a + b | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
firmware/defmt-test/macros/tests/ui/test-has-invalid-function-signature.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: `#[test]` function must have signature `fn([&mut Type])` (parameter is optional) | ||
--> tests/ui/test-has-invalid-function-signature.rs:6:8 | ||
| | ||
6 | fn hello(a: i32, b: i32) -> i32 { | ||
| ^^^^^ |
14 changes: 14 additions & 0 deletions
14
firmware/defmt-test/macros/tests/ui/test-has-non-empty-signature.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
fn main() {} | ||
|
||
#[defmt_test_macros::tests] | ||
mod tests { | ||
#[init] | ||
fn init() { | ||
// empty | ||
} | ||
|
||
#[test] | ||
fn test(arg: &mut u8) { | ||
assert!(true); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
firmware/defmt-test/macros/tests/ui/test-has-non-empty-signature.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: no state was initialized by `#[init]`; signature must be `fn()` | ||
--> tests/ui/test-has-non-empty-signature.rs:11:8 | ||
| | ||
11 | fn test(arg: &mut u8) { | ||
| ^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fn main() {} | ||
|
||
#[defmt_test_macros::tests(tests)] | ||
mod tests { | ||
} |
7 changes: 7 additions & 0 deletions
7
firmware/defmt-test/macros/tests/ui/tests-has-argument.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
error: `#[test]` attribute takes no arguments | ||
justahero marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--> tests/ui/tests-has-argument.rs:3:1 | ||
| | ||
3 | #[defmt_test_macros::tests(tests)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: this error originates in the attribute macro `defmt_test_macros::tests` (in Nightly builds, run with -Z macro-backtrace for more info) |
7 changes: 7 additions & 0 deletions
7
firmware/defmt-test/macros/tests/ui/tests-without-annotated-function.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
fn main() {} | ||
|
||
#[defmt_test_macros::tests] | ||
mod tests { | ||
fn some_function() { | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
firmware/defmt-test/macros/tests/ui/tests-without-annotated-function.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: function requires `#[init]` or `#[test]` attribute | ||
--> tests/ui/tests-without-annotated-function.rs:5:5 | ||
| | ||
5 | fn some_function() { | ||
| ^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
(1/7) running `change_init_struct`... | ||
(2/7) running `test_for_changed_init_struct`... | ||
(3/7) running `assert_true`... | ||
(4/7) running `assert_imported_max`... | ||
(5/7) running `result`... | ||
(6/7) running `should_error`... | ||
(7/7) running `fail`... | ||
(1/8) running `change_init_struct`... | ||
(2/8) running `test_for_changed_init_struct`... | ||
(3/8) running `assert_true`... | ||
(4/8) running `assert_imported_max`... | ||
(5/8) running `result`... | ||
(6/8) running `should_error`... | ||
(7/8) ignoring `ignored`... | ||
(8/8) running `fail`... | ||
ERROR panicked at '`#[should_error]` test failed with outcome: Ok(this should have returned `Err`)' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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