Skip to main content

reinhardt_testkit/
logging.rs

1//! Test logging utilities for Reinhardt framework
2//!
3//! Provides utilities for initializing logging in test environments.
4
5use std::sync::Once;
6
7static INIT: Once = Once::new();
8
9/// Initialize logging for tests (call once)
10///
11/// This function ensures that logging is initialized only once across all tests.
12/// It uses `env_logger` with test mode enabled.
13///
14/// # Examples
15///
16/// ```
17/// use reinhardt_testkit::logging::init_test_logging;
18///
19/// // In your test:
20/// init_test_logging();
21/// // Your test code
22/// ```
23pub fn init_test_logging() {
24	INIT.call_once(|| {
25		let _ = env_logger::builder().is_test(true).try_init();
26	});
27}
28
29#[cfg(test)]
30mod tests {
31	use super::*;
32	use rstest::rstest;
33
34	#[rstest]
35	fn test_init_test_logging_succeeds() {
36		// Arrange / Act (should not panic)
37		init_test_logging();
38
39		// Assert - if we reach here, initialization succeeded
40		assert!(true);
41	}
42
43	#[rstest]
44	fn test_init_test_logging_idempotent() {
45		// Arrange / Act - calling multiple times should not panic
46		init_test_logging();
47		init_test_logging();
48		init_test_logging();
49
50		// Assert - multiple calls are safe due to Once guard
51		assert!(true);
52	}
53}