rch_common/testing/mod.rs
1//! Test utilities for RCH.
2//!
3//! Provides structured test logging, output capture, and debugging infrastructure
4//! for consistent test output across the codebase.
5//!
6//! # Features
7//!
8//! - JSONL test logs for CI debugging
9//! - Structured phase markers (TEST START/PASS/FAIL)
10//! - Terminal metadata capture
11//! - Zero-boilerplate logging with `TestGuard`
12//!
13//! # Quick Start (Unit Tests)
14//!
15//! For simple unit tests, use `TestGuard` which auto-logs pass/fail:
16//!
17//! ```ignore
18//! use rch_common::testing::TestGuard;
19//!
20//! #[test]
21//! fn test_simple() {
22//! let _guard = TestGuard::new("test_simple");
23//! // ... test logic ...
24//! // TEST PASS logged automatically on success
25//! // TEST FAIL logged automatically if test panics
26//! }
27//! ```
28//!
29//! Or use the macro for automatic name detection:
30//!
31//! ```ignore
32//! use rch_common::test_guard;
33//!
34//! #[test]
35//! fn test_auto_name() {
36//! let _guard = test_guard!(); // Uses "test_auto_name" as the test name
37//! assert_eq!(1 + 1, 2);
38//! }
39//! ```
40//!
41//! # Detailed Logging (E2E/Integration Tests)
42//!
43//! For tests that need detailed phase logging, use `TestLogger`:
44//!
45//! ```ignore
46//! use rch_common::testing::{TestLogger, TestPhase};
47//!
48//! #[test]
49//! fn test_detailed() {
50//! let logger = TestLogger::for_test("test_detailed");
51//! logger.log(TestPhase::Setup, "Initializing test state");
52//! // ... test logic ...
53//! logger.log(TestPhase::Verify, "Checking results");
54//! logger.pass(); // or logger.fail("reason")
55//! }
56//! ```
57//!
58//! # Environment Variables
59//!
60//! - `RCH_TEST_LOGGING=1`: Force enable structured logging
61//! - `RCH_TEST_LOGGING=0`: Force disable (fastest, no I/O)
62//! - Default: Enabled in CI (`CI=true`), disabled locally
63
64mod log;
65
66pub use log::{
67 TerminalInfo, TestGuard, TestLogEntry, TestLogger, TestPhase, TestResult,
68 init_global_test_logging,
69};