#![allow(dead_code)]
pub mod assertions;
pub mod e2e_harness;
pub mod fake_terminal;
pub mod fixtures;
pub mod flaky;
pub mod platform;
pub mod validation;
use std::sync::Once;
use tracing_subscriber::{EnvFilter, fmt, layer::SubscriberExt, util::SubscriberInitExt};
static INIT: Once = Once::new();
pub fn init_test_logging() {
INIT.call_once(|| {
let use_json = std::env::var("TEST_LOG_JSON").is_ok();
let env_filter = EnvFilter::try_from_default_env()
.unwrap_or_else(|_| EnvFilter::new("rich_rust=debug,test=info"));
if use_json {
tracing_subscriber::registry()
.with(env_filter)
.with(fmt::layer().json().with_test_writer())
.try_init()
.ok();
} else {
tracing_subscriber::registry()
.with(env_filter)
.with(
fmt::layer()
.with_test_writer()
.with_ansi(true)
.with_file(true)
.with_line_number(true)
.with_thread_ids(true)
.with_target(true)
.compact(),
)
.try_init()
.ok();
}
});
}
pub fn init_test_logging_with_filter(filter: &str) {
INIT.call_once(|| {
let env_filter =
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(filter));
tracing_subscriber::registry()
.with(env_filter)
.with(
fmt::layer()
.with_test_writer()
.with_ansi(true)
.with_file(true)
.with_line_number(true)
.with_thread_ids(true)
.with_target(true)
.compact(),
)
.try_init()
.ok();
});
}
pub fn test_phase(name: &str) -> tracing::span::EnteredSpan {
let span = tracing::info_span!("test_phase", phase = name);
tracing::info!(phase = name, "entering test phase");
span.entered()
}
pub fn log_test_context(test_name: &str, description: &str) {
tracing::info!(
test_name = test_name,
description = description,
"test context"
);
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_init_logging_is_idempotent() {
init_test_logging();
init_test_logging();
init_test_logging();
}
#[test]
fn test_logging_produces_output() {
init_test_logging();
tracing::debug!("This is a debug message");
tracing::info!("This is an info message");
tracing::warn!("This is a warning message");
}
#[test]
fn test_phase_logging() {
init_test_logging();
{
let _setup = test_phase("setup");
tracing::debug!("Setting up test resources");
}
{
let _execute = test_phase("execute");
tracing::debug!("Executing test logic");
}
{
let _verify = test_phase("verify");
tracing::debug!("Verifying results");
}
}
}