update panic hook for zebra-test to supress confusing output (#1065)
* update panic hook for zebra-test to supress confusing output * remove outdated comment
This commit is contained in:
parent
95f2463188
commit
bd861fd25e
|
|
@ -3310,6 +3310,7 @@ dependencies = [
|
||||||
"futures",
|
"futures",
|
||||||
"hex",
|
"hex",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
"owo-colors",
|
||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
"regex",
|
"regex",
|
||||||
"spandoc",
|
"spandoc",
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ spandoc = "0.2.0"
|
||||||
regex = "1.3.9"
|
regex = "1.3.9"
|
||||||
thiserror = "1.0.20"
|
thiserror = "1.0.20"
|
||||||
pretty_assertions = "0.6.1"
|
pretty_assertions = "0.6.1"
|
||||||
|
owo-colors = "1.1.3"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tokio = { version = "0.2", features = ["full"] }
|
tokio = { version = "0.2", features = ["full"] }
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
//! Miscellaneous test code for Zebra.
|
//! Miscellaneous test code for Zebra.
|
||||||
use std::sync::Once;
|
use color_eyre::section::PanicMessage;
|
||||||
|
use owo_colors::OwoColorize;
|
||||||
use tracing_error::ErrorLayer;
|
use tracing_error::ErrorLayer;
|
||||||
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
||||||
|
|
||||||
|
use std::sync::Once;
|
||||||
|
|
||||||
pub mod command;
|
pub mod command;
|
||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
pub mod transcript;
|
pub mod transcript;
|
||||||
|
|
@ -70,14 +73,49 @@ pub fn init() {
|
||||||
});
|
});
|
||||||
}))
|
}))
|
||||||
.display_env_section(false)
|
.display_env_section(false)
|
||||||
// Once I make a release with
|
.panic_message(SkipTestReturnedErrPanicMessages)
|
||||||
// https://github.com/yaahc/color-eyre/pull/57 I'm going to add a
|
|
||||||
// custom PanicMessage handler for skipping the message in panics
|
|
||||||
// when the message is the exact one created by panics in tests that
|
|
||||||
// returned an Err. It will still print the content of the Err in
|
|
||||||
// the case where an error is returned.
|
|
||||||
// .panic_message(SkipTestReturnedErrPanicMessages)
|
|
||||||
.install()
|
.install()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct SkipTestReturnedErrPanicMessages;
|
||||||
|
|
||||||
|
impl PanicMessage for SkipTestReturnedErrPanicMessages {
|
||||||
|
fn display(
|
||||||
|
&self,
|
||||||
|
pi: &std::panic::PanicInfo<'_>,
|
||||||
|
f: &mut std::fmt::Formatter<'_>,
|
||||||
|
) -> std::fmt::Result {
|
||||||
|
let payload = pi
|
||||||
|
.payload()
|
||||||
|
.downcast_ref::<String>()
|
||||||
|
.map(String::as_str)
|
||||||
|
.or_else(|| pi.payload().downcast_ref::<&str>().cloned())
|
||||||
|
.unwrap_or("<non string panic payload>");
|
||||||
|
|
||||||
|
// 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, "<unknown>")?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue