| Crates.io | tanu-derive |
| lib.rs | tanu-derive |
| version | 0.10.0 |
| created_at | 2025-01-30 13:48:57.308707+00 |
| updated_at | 2025-09-18 02:46:34.574558+00 |
| description | Offering #[tanu::test] and #[tanu::main] macros |
| homepage | https://github.com/tanu-rs/tanu |
| repository | https://github.com/tanu-rs/tanu |
| max_upload_size | |
| id | 1536401 |
| size | 32,349 |
Procedural macros for the tanu WebAPI testing framework.
tanu-derive provides the essential procedural macros that power the tanu testing framework:
#[tanu::test] - Transforms functions into discoverable test cases#[tanu::main] - Generates the main function for test executionThese macros enable compile-time test discovery and registration, allowing the tanu framework to automatically find and execute your tests without runtime reflection.
The #[tanu::test] macro automatically registers test functions with the tanu test runner:
#[tanu::test]
async fn simple_test() -> eyre::Result<()> {
// Test implementation
Ok(())
}
Support for parameterized tests with multiple parameter sets:
#[tanu::test(200)]
#[tanu::test(404)]
#[tanu::test(500)]
async fn test_status_codes(status: u16) -> eyre::Result<()> {
// Test with different status codes
Ok(())
}
The #[tanu::main] macro generates the appropriate main function:
#[tanu::main]
#[tokio::main]
async fn main() -> eyre::Result<()> {
let runner = run();
let app = tanu::App::new();
app.run(runner).await
}
Add tanu-derive to your Cargo.toml:
[dependencies]
tanu-derive = "0.10.0"
However, tanu-derive is typically used through the main tanu crate, which re-exports these macros:
[dependencies]
tanu = "0.10.0"
#[tanu::test]The test macro supports several patterns:
Basic Test:
#[tanu::test]
async fn basic_test() -> eyre::Result<()> {
// Test code
Ok(())
}
Parameterized Test:
#[tanu::test("GET")]
#[tanu::test("POST")]
#[tanu::test("PUT")]
async fn test_http_methods(method: &str) -> eyre::Result<()> {
// Test with different HTTP methods
Ok(())
}
Multiple Parameters:
#[tanu::test(200, "OK")]
#[tanu::test(404, "Not Found")]
#[tanu::test(500, "Internal Server Error")]
async fn test_responses(status: u16, message: &str) -> eyre::Result<()> {
// Test with status code and message
Ok(())
}
#[tanu::main]The main macro generates the entry point for your test suite:
use tanu::{run, App};
#[tanu::main]
#[tokio::main]
async fn main() -> eyre::Result<()> {
let runner = run();
let app = App::new();
app.run(runner).await
}
Functions annotated with #[tanu::test] must:
async functionsResult type (typically eyre::Result<()>)The macro system integrates seamlessly with Rust's error handling:
#[tanu::test]
async fn test_with_error_handling() -> eyre::Result<()> {
let response = some_http_request().await?;
if !response.status().is_success() {
return Err(eyre::eyre!("Request failed with status: {}", response.status()));
}
Ok(())
}
The macros perform compile-time code generation, creating a test registry that can be efficiently queried at runtime. This approach eliminates the need for runtime reflection while maintaining full type safety.
tanu-derive is designed to work seamlessly with:
tanu-core for HTTP client and assertionstanu-tui for interactive test executionFor complete examples and documentation, see the main tanu repository.