embedded_test/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2#![allow(clippy::needless_doctest_main)]
3#![cfg_attr(not(doctest), doc = include_str!("../README.md"))]
4
5mod fmt;
6
7pub use embedded_test_macros::{setup, tests};
8
9#[cfg(all(feature = "panic-handler", not(feature = "ariel-os")))]
10#[panic_handler]
11fn panic(info: &core::panic::PanicInfo) -> ! {
12    error!("====================== PANIC ======================");
13
14    error!("{}", info);
15
16    semihosting::process::abort()
17}
18
19/// Private implementation details used by the proc macro.
20/// WARNING: This API is not stable and may change at any time.
21#[doc(hidden)]
22pub mod export;
23
24mod sealed {
25    pub trait Sealed {}
26    impl Sealed for () {}
27    impl<T, E> Sealed for Result<T, E> {}
28}
29
30/// Indicates whether a test succeeded or failed.
31///
32/// This is comparable to the `Termination` trait in libstd, except stable and tailored towards the
33/// needs of embedded-test. It is implemented for `()`, which always indicates success, and `Result`,
34/// where `Ok` indicates success.
35#[cfg(feature = "defmt")]
36pub trait TestOutcome: defmt::Format + sealed::Sealed {
37    fn is_success(&self) -> bool;
38}
39
40/// Indicates whether a test succeeded or failed.
41///
42/// This is comparable to the `Termination` trait in libstd, except stable and tailored towards the
43/// needs of embedded-test. It is implemented for `()`, which always indicates success, and `Result`,
44/// where `Ok` indicates success.
45#[cfg(feature = "log")]
46pub trait TestOutcome: core::fmt::Debug + sealed::Sealed {
47    fn is_success(&self) -> bool;
48}
49
50/// Indicates whether a test succeeded or failed.
51///
52/// This is comparable to the `Termination` trait in libstd, except stable and tailored towards the
53/// needs of embedded-test. It is implemented for `()`, which always indicates success, and `Result`,
54/// where `Ok` indicates success.
55#[cfg(all(not(feature = "log"), not(feature = "defmt")))]
56pub trait TestOutcome: sealed::Sealed {
57    fn is_success(&self) -> bool;
58}
59
60impl TestOutcome for () {
61    fn is_success(&self) -> bool {
62        true
63    }
64}
65
66#[cfg(feature = "log")]
67impl<T: core::fmt::Debug, E: core::fmt::Debug> TestOutcome for Result<T, E> {
68    fn is_success(&self) -> bool {
69        self.is_ok()
70    }
71}
72
73#[cfg(feature = "defmt")]
74impl<T: defmt::Format, E: defmt::Format> TestOutcome for Result<T, E> {
75    fn is_success(&self) -> bool {
76        self.is_ok()
77    }
78}
79
80#[cfg(all(not(feature = "log"), not(feature = "defmt")))]
81impl<T, E> TestOutcome for Result<T, E> {
82    fn is_success(&self) -> bool {
83        self.is_ok()
84    }
85}