Skip to content

Commit c5f5ca5

Browse files
committed
Fix clippy lint, add tests for setup macro
1 parent 3ada841 commit c5f5ca5

File tree

6 files changed

+65
-3
lines changed

6 files changed

+65
-3
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
uses: Swatinem/rust-cache@v2.7.5
8787

8888
- name: Run Compile tests
89-
run: cd tests-build && cargo test
89+
run: cd tests-build && cargo test -- --test-threads 1
9090

9191
fmt:
9292
name: Rustfmt

macros/src/attributes/tests/codegen/export_sym.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub(crate) fn export_sym(
4646
if ignore { "true" } else { "false" },
4747
if should_panic { "true" } else { "false" },
4848
if let Some(timeout) = timeout {
49-
format!(",\"timeout\":{}", timeout)
49+
format!(",\"timeout\":{timeout}")
5050
} else {
5151
String::new()
5252
}

macros/src/attributes/tests/parse/items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub(crate) fn parse_item(mut f: ItemFn) -> Result<Func, syn::Error> {
6060
Err(e) => {
6161
return Err(syn::Error::new(
6262
attr.span(),
63-
format!("failed to parse `timeout` attribute. Must be of the form #[timeout(10)] where 10 is the timeout in seconds. Error: {}", e)
63+
format!("failed to parse `timeout` attribute. Must be of the form #[timeout(10)] where 10 is the timeout in seconds. Error: {e}")
6464
));
6565
}
6666
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
```cargo
3+
[dependencies]
4+
embedded-test = { path = "../../.." }
5+
[lib]
6+
harness = false
7+
```
8+
*/
9+
10+
#![no_std]
11+
#![no_main]
12+
13+
#[cfg(test)]
14+
#[embedded_test::setup]
15+
fn setup() {}
16+
17+
mod somewhere_else {
18+
#[cfg(test)]
19+
#[embedded_test::setup]
20+
fn setup() {}
21+
}
22+
23+
#[cfg(test)]
24+
#[embedded_test::tests]
25+
mod tests {
26+
27+
#[test]
28+
fn ok() {
29+
assert!(true);
30+
}
31+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
error: symbol `_embedded_test_setup` is already defined

tests-build/cases/pass/setup.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
```cargo
3+
[dependencies]
4+
embedded-test = { path = "../../.." }
5+
rtt-target = { version = "0.6.1", features = ["log"] }
6+
log = { version = "0.4.20" }
7+
esp-hal = { version = "0.23.1", features = ["esp32c6"] } # for critical section implementation
8+
[lib]
9+
harness = false
10+
```
11+
*/
12+
13+
#![no_std]
14+
#![no_main]
15+
16+
#[cfg(test)]
17+
#[embedded_test::setup]
18+
fn setup() {
19+
rtt_target::rtt_init_log!();
20+
}
21+
22+
#[cfg(test)]
23+
#[embedded_test::tests]
24+
mod tests {
25+
use esp_hal::*; // needs to be in scope, to prevent linker error about missing `critical_section` implementation
26+
#[test]
27+
fn ok() {
28+
log::info!("Hello world");
29+
}
30+
}

0 commit comments

Comments
 (0)