embedded-test-macros 0.8.0

proc-macros for the embedded-test crate
Documentation
mod attributes;

use proc_macro::TokenStream;
use proc_macro_error2::proc_macro_error;

/// Attribute to be placed on the test suite's module.
///
/// ## Arguments
/// - `default-timeout`: The default timeout in seconds for all tests in the suite. This can be overridden on a per-test basis. If not specified here or on a per-test basis, the default timeout is 60 seconds.
/// - `executor`: The custom executor to use for running async tests. This is only required if the features `embassy` and `external-executor` are enabled.
///
/// ## Examples
///
/// Define a test suite with a single test:
///
/// ```rust,no_run
/// #[embedded_test::tests]
/// mod tests {
///     #[init]
///     fn init() {
///         // Initialize the hardware
///     }
///
///     #[test]
///     fn test() {
///        // Test the hardware
///     }
/// }
/// ```
///
/// Define a test suite and customize everything:
///
/// ```rust,no_run
/// #[embedded_test::tests(default_timeout = 10, executor = embassy::executor::Executor::new())]
/// mod tests {
///     #[init]
///     fn init() {
///         // Initialize the hardware
///     }
///
///     #[test]
///     fn test() {
///         log::info("Start....")
///         // Test the hardware
///     }
///
///     #[test]
///     #[timeout(5)]
///     fn test2() {
///        // Test the hardware
///     }
/// }
/// ```
#[proc_macro_attribute]
#[proc_macro_error]
pub fn tests(args: TokenStream, input: TokenStream) -> TokenStream {
    attributes::tests::expand(args, input)
}

/// Attribute to be placed on a global setup function for the test suite
///
/// Use this function to set up a global logger
///
/// ## Examples
///
/// ```rust,no_run
/// #[cfg(test)]
/// #[embedded_test::setup]
/// fn setup() {
///     rtt_target::rtt_init_log!();
/// }
/// ```
///
#[proc_macro_attribute]
#[proc_macro_error]
pub fn setup(args: TokenStream, input: TokenStream) -> TokenStream {
    attributes::setup::expand(args, input)
}