allure_rs/lib.rs
1//! # Allure-RS
2//!
3//! A comprehensive Rust library for generating [Allure](https://allurereport.org/) test reports.
4//!
5//! This crate provides full feature parity with allure-js-commons, including:
6//!
7//! - Test metadata annotations (epic, feature, story, severity, owner, tags)
8//! - Test steps with nesting support
9//! - Attachments (text, JSON, binary files)
10//! - BDD-style steps (given, when, then)
11//! - Links to issue trackers and test management systems
12//! - Flaky test support
13//! - Environment and categories configuration
14//!
15//! ## Quick Start
16//!
17//! Add this to your `Cargo.toml`:
18//!
19//! ```toml
20//! [dev-dependencies]
21//! allure-rs = "0.1"
22//! ```
23//!
24//! ## Basic Usage
25//!
26//! ```ignore
27//! use allure_rs::prelude::*;
28//!
29//! // Note: Metadata attributes must come BEFORE #[allure_test]
30//! #[allure_epic("User Management")]
31//! #[allure_feature("Authentication")]
32//! #[allure_severity("critical")]
33//! #[allure_test]
34//! fn test_login() {
35//! step("Initialize user", || {
36//! // setup code
37//! });
38//!
39//! step("Perform login", || {
40//! // test code
41//! assert!(true);
42//! });
43//!
44//! attachment::text("Debug info", "Login successful");
45//! }
46//! ```
47//!
48//! ## BDD Style
49//!
50//! ```ignore
51//! use allure_rs::prelude::*;
52//!
53//! #[allure_test]
54//! fn test_user_registration() {
55//! bdd::given("a new user with valid email", || {
56//! // setup
57//! });
58//!
59//! bdd::when("the user submits registration form", || {
60//! // action
61//! });
62//!
63//! bdd::then("the user account should be created", || {
64//! assert!(true);
65//! });
66//! }
67//! ```
68//!
69//! ## Configuration
70//!
71//! ```ignore
72//! use allure_rs::configure;
73//!
74//! // Initialize before running tests (e.g., in a test setup or main)
75//! configure()
76//! .results_dir("allure-results")
77//! .clean_results(true)
78//! .init()
79//! .unwrap();
80//! ```
81//!
82//! ## Environment Info
83//!
84//! ```ignore
85//! use allure_rs::environment;
86//!
87//! environment()
88//! .set("rust_version", env!("CARGO_PKG_RUST_VERSION"))
89//! .set("os", std::env::consts::OS)
90//! .set_from_env("CI", "CI")
91//! .write()
92//! .unwrap();
93//! ```
94//!
95//! ## Categories
96//!
97//! ```ignore
98//! use allure_rs::{categories, Category, Status};
99//!
100//! categories()
101//! .with_product_defects()
102//! .with_test_defects()
103//! .with_category(
104//! Category::new("Infrastructure Issues")
105//! .with_status(Status::Broken)
106//! .with_message_regex(".*timeout.*")
107//! )
108//! .write()
109//! .unwrap();
110//! ```
111
112// Re-export everything from allure-core
113pub use allure_core::*;
114
115// Hidden re-export of allure_core for macro-generated code.
116// This allows users to only depend on allure-rs without needing
117// a separate allure-core dependency.
118#[doc(hidden)]
119pub use allure_core as __private;
120
121// Re-export all proc macros
122pub use allure_macros::{
123 allure_description, allure_description_html, allure_epic, allure_epics, allure_feature,
124 allure_features, allure_flaky, allure_id, allure_issue, allure_link, allure_owner,
125 allure_parent_suite, allure_severity, allure_step, allure_step_fn, allure_stories,
126 allure_story, allure_sub_suite, allure_suite, allure_suite_label, allure_tag, allure_tags,
127 allure_test, allure_title, allure_tms,
128};
129
130/// Prelude module for convenient imports.
131///
132/// Use `use allure_rs::prelude::*;` to import commonly used items.
133pub mod prelude {
134 // Proc macros
135 pub use allure_macros::{
136 allure_description, allure_description_html, allure_epic, allure_epics, allure_feature,
137 allure_features, allure_flaky, allure_id, allure_issue, allure_link, allure_owner,
138 allure_parent_suite, allure_severity, allure_step, allure_step_fn, allure_stories,
139 allure_story, allure_sub_suite, allure_suite, allure_suite_label, allure_tag, allure_tags,
140 allure_test, allure_title, allure_tms,
141 };
142
143 // Core types
144 pub use allure_core::{
145 Attachment, Category, Label, Link, Parameter, Severity, Status, StepResult, TestResult,
146 };
147
148 // Runtime functions
149 pub use allure_core::{
150 allure_id, attach_binary, attach_file, attach_json, attach_text, configure, description,
151 description_html, display_name, epic, feature, flaky, issue, known_issue, label, link,
152 log_step, owner, parameter, parameter_excluded, parameter_hidden, parameter_masked,
153 parent_suite, run_test, severity, skip, step, story, sub_suite, suite, tag, tags,
154 test_case_id, title, tms, with_test_context,
155 };
156
157 // Attachment module
158 pub use allure_core::attachment;
159
160 // BDD module
161 pub use allure_core::bdd;
162}
163
164#[cfg(test)]
165mod tests {
166 #[test]
167 fn test_prelude_imports() {
168 // Verify that prelude provides the expected items
169 use crate::prelude::*;
170
171 // This just verifies compilation
172 let _ = Status::Passed;
173 let _ = Severity::Critical;
174 }
175}