embedded_test_macros/lib.rs
1mod attributes;
2
3use proc_macro::TokenStream;
4use proc_macro_error2::proc_macro_error;
5
6/// Attribute to be placed on the test suite's module.
7///
8/// ## Arguments
9/// - `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.
10/// - `executor`: The custom executor to use for running async tests. This is only required if the features `embassy` and `external-executor` are enabled.
11///
12/// ## Examples
13///
14/// Define a test suite with a single test:
15///
16/// ```rust,no_run
17/// #[embedded_test::tests]
18/// mod tests {
19/// #[init]
20/// fn init() {
21/// // Initialize the hardware
22/// }
23///
24/// #[test]
25/// fn test() {
26/// // Test the hardware
27/// }
28/// }
29/// ```
30///
31/// Define a test suite and customize everything:
32///
33/// ```rust,no_run
34/// #[embedded_test::tests(default_timeout = 10, executor = embassy::executor::Executor::new())]
35/// mod tests {
36/// #[init]
37/// fn init() {
38/// // Initialize the hardware
39/// }
40///
41/// #[test]
42/// fn test() {
43/// log::info("Start....")
44/// // Test the hardware
45/// }
46///
47/// #[test]
48/// #[timeout(5)]
49/// fn test2() {
50/// // Test the hardware
51/// }
52/// }
53/// ```
54#[proc_macro_attribute]
55#[proc_macro_error]
56pub fn tests(args: TokenStream, input: TokenStream) -> TokenStream {
57 attributes::tests::expand(args, input)
58}
59
60/// Attribute to be placed on a global setup function for the test suite
61///
62/// Use this function to set up a global logger
63///
64/// ## Examples
65///
66/// ```rust,no_run
67/// #[cfg(test)]
68/// #[embedded_test::setup]
69/// fn setup() {
70/// rtt_target::rtt_init_log!();
71/// }
72/// ```
73///
74#[proc_macro_attribute]
75#[proc_macro_error]
76pub fn setup(args: TokenStream, input: TokenStream) -> TokenStream {
77 attributes::setup::expand(args, input)
78}