clnrm_core/reporting/
mod.rs

1//! Report generation for test results
2//!
3//! Provides multi-format report generation including JSON, JUnit XML, and SHA-256 digest.
4//! All reports support proper error handling and follow core team standards.
5
6pub mod digest;
7pub mod json;
8pub mod junit;
9
10use crate::error::Result;
11use crate::validation::ValidationReport;
12use std::path::Path;
13
14pub use digest::DigestReporter;
15pub use json::JsonReporter;
16pub use junit::JunitReporter;
17
18/// Report configuration
19#[derive(Debug, Clone, Default)]
20pub struct ReportConfig {
21    /// Path for JSON report output
22    pub json_path: Option<String>,
23    /// Path for JUnit XML report output
24    pub junit_path: Option<String>,
25    /// Path for SHA-256 digest output
26    pub digest_path: Option<String>,
27}
28
29impl ReportConfig {
30    /// Create new empty report configuration
31    pub fn new() -> Self {
32        Self::default()
33    }
34
35    /// Set JSON report path
36    pub fn with_json(mut self, path: impl Into<String>) -> Self {
37        self.json_path = Some(path.into());
38        self
39    }
40
41    /// Set JUnit XML report path
42    pub fn with_junit(mut self, path: impl Into<String>) -> Self {
43        self.junit_path = Some(path.into());
44        self
45    }
46
47    /// Set digest report path
48    pub fn with_digest(mut self, path: impl Into<String>) -> Self {
49        self.digest_path = Some(path.into());
50        self
51    }
52}
53
54/// Generate all configured reports
55///
56/// # Arguments
57/// * `config` - Report configuration specifying which reports to generate
58/// * `report` - Validation report containing test results
59/// * `spans_json` - Raw JSON string of spans for digest calculation
60///
61/// # Returns
62/// * `Result<()>` - Success or first encountered error
63///
64/// # Errors
65/// Returns error if any report generation fails
66pub fn generate_reports(
67    config: &ReportConfig,
68    report: &ValidationReport,
69    spans_json: &str,
70) -> Result<()> {
71    if let Some(ref json_path) = config.json_path {
72        JsonReporter::write(Path::new(json_path), report)?;
73    }
74
75    if let Some(ref junit_path) = config.junit_path {
76        JunitReporter::write(Path::new(junit_path), report)?;
77    }
78
79    if let Some(ref digest_path) = config.digest_path {
80        DigestReporter::write(Path::new(digest_path), spans_json)?;
81    }
82
83    Ok(())
84}