tanu/lib.rs
1//! # Tanu - High-performance WebAPI Testing Framework
2//!
3//! Tanu is a high-performance, async-friendly, and ergonomic WebAPI testing framework for Rust.
4//! It's designed to be fast, type-safe, and easily extensible with full support for concurrency
5//! and async operations.
6//!
7//! ## Quick Start
8//!
9//! Add tanu to your `Cargo.toml`:
10//!
11//! ```toml
12//! [dependencies]
13//! tanu = "0.7"
14//! tokio = { version = "1.0", features = ["full"] }
15//! ```
16//!
17//! Write your first test:
18//!
19//! ```rust,no_run
20//! use tanu::{check, eyre, http::Client};
21//!
22//! #[tanu::test]
23//! async fn get_users() -> eyre::Result<()> {
24//! let client = Client::new();
25//! let response = client
26//! .get("https://api.example.com/users")
27//! .send()
28//! .await?;
29//!
30//! check!(response.status().is_success());
31//! Ok(())
32//! }
33//!
34//! #[tanu::main]
35//! #[tokio::main]
36//! async fn main() -> eyre::Result<()> {
37//! let runner = run();
38//! let app = tanu::App::new();
39//! app.run(runner).await?;
40//! Ok(())
41//! }
42//! ```
43//!
44//! ## Key Features
45//!
46//! - **Async/Await Native**: Full support for async operations without boilerplate
47//! - **Type-Safe**: Leverage Rust's type system for robust API testing
48//! - **Ergonomic Assertions**: Use `check!`, `check_eq!`, and other assertion macros
49//! - **Parameterized Testing**: Test multiple scenarios with different inputs
50//! - **Built-in HTTP Client**: No need to set up reqwest or other HTTP clients manually
51//! - **Flexible Error Handling**: Supports `eyre::Result`, `anyhow::Result`, and custom error types
52//! - **TUI Support**: Interactive terminal interface for test execution
53//! - **Concurrent Execution**: Run tests in parallel for better performance
54//!
55//! ## Error Types
56//!
57//! Tanu supports various Result types for flexible error handling:
58//!
59//! - `eyre::Result<()>` (recommended) - Provides colored backtraces and seamless integration
60//! - `anyhow::Result<()>` - Compatible with existing anyhow-based code
61//! - `std::result::Result<(), E>` - Standard Rust Result type with custom error types
62//!
63//! ## Examples
64//!
65//! ### Basic HTTP Test
66//!
67//! ```rust,no_run
68//! use tanu::{check_eq, eyre, http::Client};
69//!
70//! #[tanu::test]
71//! async fn test_api_endpoint() -> eyre::Result<()> {
72//! let client = Client::new();
73//! let response = client
74//! .get("https://httpbin.org/json")
75//! .header("accept", "application/json")
76//! .send()
77//! .await?;
78//!
79//! check_eq!(200, response.status().as_u16());
80//!
81//! let data: serde_json::Value = response.json().await?;
82//! check!(data.is_object());
83//!
84//! Ok(())
85//! }
86//! ```
87//!
88//! ### Parameterized Tests
89//!
90//! ```rust,no_run
91//! use tanu::{check_eq, eyre, http::Client};
92//!
93//! #[tanu::test(200)]
94//! #[tanu::test(404)]
95//! #[tanu::test(500)]
96//! async fn test_status_codes(expected_status: u16) -> eyre::Result<()> {
97//! let client = Client::new();
98//! let response = client
99//! .get(&format!("https://httpbin.org/status/{expected_status}"))
100//! .send()
101//! .await?;
102//!
103//! check_eq!(expected_status, response.status().as_u16());
104//! Ok(())
105//! }
106//! ```
107
108mod app;
109
110// Re-export procedural macros for test and main attributes
111pub use tanu_derive::{main, test};
112
113// Re-export error handling crates for user convenience
114pub use anyhow;
115pub use eyre;
116pub use pretty_assertions;
117
118// Re-export main application struct
119pub use app::App;
120
121// Re-export core functionality
122pub use tanu_core::{
123 assertion,
124 config::{get_config, get_tanu_config, Config, ProjectConfig},
125 http,
126 reporter::{ListReporter, NullReporter, Reporter, ReporterType, TableReporter},
127 runner::{self, Runner, TestInfo},
128 {check, check_eq, check_ne, check_str_eq},
129};