-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
618: Support #[ignore] attribute in defmt_test r=japaric a=justahero This PR adds support for the `#[ignore]` attribute in `defmt_test` to solve #390. Similar to the [`ignore`](https://doc.rust-lang.org/reference/attributes/testing.html#the-ignore-attribute) attribute, tests can be annotated with the attribute to ignore particular tests. * use [`trybuild`](https://github.com/dtolnay/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 Co-authored-by: Sebastian Ziebell <sebastian.ziebell@asquera.de>
- Loading branch information
Showing
29 changed files
with
231 additions
and
12 deletions.
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 | ||
--> 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) { | ||
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 | ||
--> 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