//! Miscellaneous test code for Zebra. // Each lazy_static variable uses additional recursion #![recursion_limit = "256"] // Disable some broken or unwanted clippy nightly lints // Build without warnings on nightly 2021-01-17 and later and stable 1.51 and later #![allow(unknown_lints)] // Disable old lint warnings on nightly until 1.51 is stable #![allow(renamed_and_removed_lints)] // Use the old lint name to build without warnings on stable until 1.51 is stable #![allow(clippy::unknown_clippy_lints)] // The actual lints we want to disable #![allow(clippy::from_iter_instead_of_collect)] use color_eyre::section::PanicMessage; use owo_colors::OwoColorize; use tracing_error::ErrorLayer; use tracing_subscriber::{fmt, prelude::*, EnvFilter}; use std::sync::Once; pub mod command; pub mod prelude; pub mod transcript; pub mod vectors; static INIT: Once = Once::new(); /// Initialize globals for tests such as the tracing subscriber and panic / error /// reporting hooks pub fn init() { INIT.call_once(|| { let fmt_layer = fmt::layer().with_target(false); // Use the RUST_LOG env var, or by default: // - warn for most tests, and // - for some modules, hide expected warn logs let filter_layer = EnvFilter::try_from_default_env().unwrap_or_else(|_| { EnvFilter::try_new("warn") .unwrap() .add_directive("zebra_consensus=error".parse().unwrap()) }); tracing_subscriber::registry() .with(filter_layer) .with(fmt_layer) .with(ErrorLayer::default()) .init(); color_eyre::config::HookBuilder::default() .add_frame_filter(Box::new(|frames| { let mut displayed = std::collections::HashSet::new(); let filters = &[ "tokio::", ", f: &mut std::fmt::Formatter<'_>, ) -> std::fmt::Result { let payload = pi .payload() .downcast_ref::() .map(String::as_str) .or_else(|| pi.payload().downcast_ref::<&str>().cloned()) .unwrap_or(""); // skip panic output that is clearly from tests that returned an `Err` // and assume that the test handler has already printed the value inside // of the `Err`. if payload.contains("the test returned a termination value with a non-zero status code") { return write!(f, "---- end of test output ----"); } writeln!(f, "{}", "\nThe application panicked (crashed).".red())?; write!(f, "Message: ")?; writeln!(f, "{}", payload.cyan())?; // If known, print panic location. write!(f, "Location: ")?; if let Some(loc) = pi.location() { write!(f, "{}", loc.file().purple())?; write!(f, ":")?; write!(f, "{}", loc.line().purple())?; } else { write!(f, "")?; } Ok(()) } }