From 1ebc0ac43f18e6919dd98c1cb49934f24c9c1a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Vi=C3=B6l?= Date: Fri, 4 Jun 2021 23:40:00 +0200 Subject: [PATCH] Disable test harness for lib target Without this change, if `testsuite/src/lib.rs` will be crated and `cargo test` is invoked, cargo will try to link libtest with the crate. As this crate is `no_std` and will usually be run for targets, where no std library exists and therefor also no libtest, this will fail with an error similar to this: error[E0463]: can't find crate for `test` error: aborting due to previous error For more information about this error, try `rustc --explain E0463`. error: could not compile `testsuite` To circumvent this issue, disable the harness for lib as well. Because the crates lib.rs is handled as a binary for test mode, rust will look for a main function. Add a minimal lib.rs, so that it will compile and run, when test is invoked. --- testsuite/Cargo.toml | 3 +++ testsuite/src/lib.rs | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 testsuite/src/lib.rs diff --git a/testsuite/Cargo.toml b/testsuite/Cargo.toml index 5078a98..3567356 100644 --- a/testsuite/Cargo.toml +++ b/testsuite/Cargo.toml @@ -6,6 +6,9 @@ publish = false edition = "2018" version = "0.1.0" +[lib] +harness = false + [[test]] name = "test" harness = false diff --git a/testsuite/src/lib.rs b/testsuite/src/lib.rs new file mode 100644 index 0000000..d4dd9ce --- /dev/null +++ b/testsuite/src/lib.rs @@ -0,0 +1,7 @@ +#![no_std] +#![cfg_attr(test, no_main)] + +use {{crate_name}} as _; // memory layout + panic handler + +#[defmt_test::tests] +mod tests {}