defmt_test/
lib.rs

1//! A test harness for embedded devices.
2//!
3//! This crate has a single API: the `#[tests]` macro. This macro is documented in the project
4//! README which can be found at:
5//!
6//! - <https://crates.io/crates/defmt-test> (crates.io version)
7//! - <https://github.com/knurling-rs/defmt/tree/main/firmware/defmt-test> (git version)
8
9#![doc(html_logo_url = "https://knurling.ferrous-systems.com/knurling_logo_light_text.svg")]
10#![no_std]
11
12use defmt::Format;
13pub use defmt_test_macros::tests;
14
15/// Private implementation details used by the proc macro.
16#[doc(hidden)]
17pub mod export;
18
19mod sealed {
20    pub trait Sealed {}
21    impl Sealed for () {}
22    impl<T, E> Sealed for Result<T, E> {}
23}
24
25/// Indicates whether a test succeeded or failed.
26///
27/// This is comparable to the `Termination` trait in libstd, except stable and tailored towards the
28/// needs of defmt-test. It is implemented for `()`, which always indicates success, and `Result`,
29/// where `Ok` indicates success.
30pub trait TestOutcome: Format + sealed::Sealed {
31    fn is_success(&self) -> bool;
32}
33
34impl TestOutcome for () {
35    fn is_success(&self) -> bool {
36        true
37    }
38}
39
40impl<T: Format, E: Format> TestOutcome for Result<T, E> {
41    fn is_success(&self) -> bool {
42        self.is_ok()
43    }
44}