use color_eyre::eyre::{self, WrapErr}; use std::sync::Mutex; pub type TestResult = eyre::Result; static COLOR_EYRE_INSTALLED: Mutex = Mutex::new(false); pub(super) fn install() { let mut lock = COLOR_EYRE_INSTALLED.lock().unwrap(); if !*lock { let _ = color_eyre::install(); *lock = true; } } macro_rules! ensure_eq { ($left:expr, $right:expr $(,)?) => { match (&$left, &$right) { (left_val, right_val) => { ::color_eyre::eyre::ensure!((left_val == right_val), r#"assertion failed: `(left == right)` left: `{:?}`, right: `{:?}`"#, left_val, right_val); } } }; ($left:expr, $right:expr, $($arg:tt)+) => { match (&$left, &$right) { (left_val, right_val) => { ::color_eyre::eyre::ensure!((left_val == right_val), r#"assertion failed: `(left == right)` left: `{:?}`, right: `{:?}`: {}"#, left_val, right_val, ::core::format_args!($($arg)+)); } } }; } pub trait WrapErrExt: WrapErr + Sized { fn opname(self, loc: &str) -> eyre::Result { self.wrap_err_with(|| format!("{loc} failed")) } } impl> WrapErrExt for WE {}