Skip to main content

behave_macros/
lib.rs

1//! Proc macros for the behave BDD testing framework.
2//!
3//! This crate is an implementation detail of [`behave`]. Do not depend on it
4//! directly - use `behave` instead.
5#![allow(unreachable_pub)]
6
7mod codegen;
8mod parse;
9mod slug;
10
11/// Defines BDD-style test suites using a zero-keyword DSL.
12///
13/// # Examples
14///
15/// ```rust,ignore
16/// use behave::prelude::*;
17///
18/// behave! {
19///     "addition" {
20///         "adds two numbers" {
21///             expect!(1 + 1).to_equal(&2)?;
22///         }
23///     }
24/// }
25/// ```
26#[proc_macro]
27pub fn behave(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
28    let input = syn::parse_macro_input!(input as parse::BehaveInput);
29    match codegen::generate(input) {
30        Ok(tokens) => tokens.into(),
31        Err(err) => err.to_compile_error().into(),
32    }
33}