1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copied from https://github.com/knurling-rs/defmt/blob/main/firmware/defmt-test/src/lib.rs

#![feature(trait_alias)]
#![cfg_attr(target_os ="none", no_std)]


cfg_if::cfg_if! {
    if #[cfg(target_os ="none")]
    {
mod semihosting_ext;

pub use embedded_test_macros::tests;

#[cfg(feature = "defmt")]
pub trait FormatOrDebug = defmt::Format;
#[cfg(feature = "log")]
pub trait FormatOrDebug = core::fmt::Debug;


/// Private implementation details used by the proc macro.
#[doc(hidden)]
pub mod export;

mod sealed {
    pub trait Sealed {}
    impl Sealed for () {}
    impl<T, E> Sealed for Result<T, E> {}
}

/// Indicates whether a test succeeded or failed.
///
/// This is comparable to the `Termination` trait in libstd, except stable and tailored towards the
/// needs of embedded-test. It is implemented for `()`, which always indicates success, and `Result`,
/// where `Ok` indicates success.
pub trait TestOutcome: FormatOrDebug + sealed::Sealed {
    fn is_success(&self) -> bool;
}

impl TestOutcome for () {
    fn is_success(&self) -> bool {
        true
    }
}

impl<T: FormatOrDebug, E: FormatOrDebug> TestOutcome for Result<T, E> {
    fn is_success(&self) -> bool {
        self.is_ok()
    }
}

}
}