Skip to main content

camber_macros/
lib.rs

1//! Procedural macros for Camber.
2//!
3//! Currently this crate exposes the `#[camber::test]` attribute for async tests
4//! that need a Tokio runtime with Camber context installed.
5
6mod expand;
7
8use proc_macro::TokenStream;
9use syn::{ItemFn, parse_macro_input};
10
11/// Marks an async function as a Camber test.
12///
13/// Sets up a multi-thread Tokio runtime with Camber context installed.
14/// The test body runs as an async block inside `camber::runtime::__test_async`.
15///
16/// ```ignore
17/// #[camber::test]
18/// async fn my_test() {
19///     let handle = camber::spawn_async(async { 42 });
20///     assert_eq!(handle.await.unwrap(), 42);
21/// }
22/// ```
23#[proc_macro_attribute]
24pub fn test(_attr: TokenStream, item: TokenStream) -> TokenStream {
25    let input = parse_macro_input!(item as ItemFn);
26    expand::expand_test(input).into()
27}