bern_test/
lib.rs

1//! On target test framework for microcontrollers.
2//!
3//! Based on `defmt-test` but not dependent on architecture or serial interface.
4//!
5//! # Features
6//! - `autorun`: Run tests without user interaction
7//! - `serial`: Use serial interface for transport
8//! - `rtt`: Use RTT for transport
9//! - `colored`: Use terminal colors
10
11#![no_std]
12
13#[cfg(feature = "serial")]
14pub mod serial;
15#[cfg(feature = "serial")]
16#[doc(hidden)]
17pub mod console;
18#[doc(hidden)]
19pub mod run_all;
20
21pub use bern_test_macros::tests;
22
23#[cfg(feature = "rtt")]
24pub use rtt_target;
25
26use core::panic::PanicInfo;
27
28#[doc(hidden)]
29pub fn test_succeeded() {
30    println!(term_green!("ok"));
31    run_all::test_succeeded();
32}
33
34#[doc(hidden)]
35pub fn test_failed(message: &str) {
36    println!(term_red!("FAILED"));
37    println!("{}", message);
38}
39
40#[doc(hidden)]
41pub fn test_panicked(info: &PanicInfo) {
42    println!(term_red!("FAILED"));
43    println!(" └─ stdout:\n{}", info);
44}
45
46#[cfg(feature = "serial")]
47#[macro_export]
48macro_rules! println {
49    ($($args:tt)*) => {
50        {
51            $crate::sprintln!($($args)*);
52        }
53    }
54}
55
56#[cfg(feature = "serial")]
57#[macro_export]
58macro_rules! print {
59    ($($args:tt)*) => {
60        {
61            $crate::sprint!($($args)*);
62        }
63    }
64}
65
66#[cfg(feature = "rtt")]
67#[macro_export]
68macro_rules! println {
69    ($($args:tt)*) => {
70        {
71            rtt_target::rprintln!($($args)*);
72        }
73    }
74}
75
76#[cfg(feature = "rtt")]
77#[macro_export]
78macro_rules! print {
79    ($($args:tt)*) => {
80        {
81            rtt_target::rprint!($($args)*);
82        }
83    }
84}
85
86#[doc(hidden)]
87pub fn get_version() -> &'static str {
88    env!("CARGO_PKG_VERSION")
89}
90
91#[doc(hidden)]
92pub fn is_autorun_enabled() -> bool {
93    #[cfg(feature = "autorun")]
94    return true;
95    #[cfg(not(feature = "autorun"))]
96    return false;
97}