mirror of https://github.com/zkat/miette.git
fix(reporter): fix reporter and tests... again
This commit is contained in:
parent
0d2e3312a4
commit
d201dde4b5
|
|
@ -66,12 +66,12 @@ Next, we have to implement the `Diagnostic` trait for it:
|
|||
use miette::{Diagnostic, Severity, DiagnosticSnippet};
|
||||
|
||||
impl Diagnostic for MyBad {
|
||||
fn code(&self) -> &(dyn std::fmt::Display + 'static) {
|
||||
&"oops::my::bad"
|
||||
fn code(&self) -> Box<dyn std::fmt::Display> {
|
||||
Box::new("oops::my::bad")
|
||||
}
|
||||
|
||||
fn help(&self) -> Option<&(dyn std::fmt::Display)> {
|
||||
Some(&"try doing it better next time?")
|
||||
fn help(&self) -> Option<Box<dyn std::fmt::Display>> {
|
||||
Some(Box::new("try doing it better next time?"))
|
||||
}
|
||||
|
||||
fn snippets(&self) -> Option<Box<dyn Iterator<Item = DiagnosticSnippet>>> {
|
||||
|
|
|
|||
|
|
@ -23,11 +23,12 @@ impl MietteReporter {
|
|||
snippet: &DiagnosticSnippet,
|
||||
) -> fmt::Result {
|
||||
use fmt::Write as _;
|
||||
write!(f, "\n[{}]", snippet.source_name)?;
|
||||
write!(f, "[{}]", snippet.source_name)?;
|
||||
if let Some(msg) = &snippet.message {
|
||||
write!(f, " {}:", msg)?;
|
||||
}
|
||||
writeln!(f)?;
|
||||
writeln!(f)?;
|
||||
let context_data = snippet
|
||||
.source
|
||||
.read_span(&snippet.context)
|
||||
|
|
@ -113,7 +114,8 @@ impl DiagnosticReporter for MietteReporter {
|
|||
writeln!(f, "{}[{}]: {}", sev, diagnostic.code(), diagnostic)?;
|
||||
|
||||
if let Some(cause) = diagnostic.source() {
|
||||
write!(f, "\n\nCaused by:")?;
|
||||
writeln!(f)?;
|
||||
write!(f, "Caused by:")?;
|
||||
let multiple = cause.source().is_some();
|
||||
|
||||
for (n, error) in Chain::new(cause).enumerate() {
|
||||
|
|
@ -127,15 +129,19 @@ impl DiagnosticReporter for MietteReporter {
|
|||
}
|
||||
|
||||
if let Some(snippets) = diagnostic.snippets() {
|
||||
writeln!(f)?;
|
||||
let mut pre = false;
|
||||
for snippet in snippets {
|
||||
if !pre {
|
||||
writeln!(f)?;
|
||||
pre = true;
|
||||
}
|
||||
self.render_snippet(f, &snippet)?;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(help) = diagnostic.help() {
|
||||
writeln!(f)?;
|
||||
write!(f, "﹦{}", help)?;
|
||||
writeln!(f, "﹦{}", help)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ fn basic() -> Result<(), MietteError> {
|
|||
};
|
||||
let out = format!("{:?}", err);
|
||||
assert_eq!(
|
||||
"Error[oops::my::bad]: oops!\n\n﹦try doing it better next time?".to_string(),
|
||||
"Error[oops::my::bad]: oops!\n\n﹦try doing it better next time?\n".to_string(),
|
||||
out
|
||||
);
|
||||
Ok(())
|
||||
|
|
@ -68,6 +68,6 @@ fn fancy() -> Result<(), MietteError> {
|
|||
};
|
||||
let out = format!("{:?}", err);
|
||||
// println!("{}", out);
|
||||
assert_eq!("Error[oops::my::bad]: oops!\n\n[bad_file.rs] This is the part that broke:\n\n 1 | source\n 2 | text\n ⫶ | ^^^^ this bit here\n 3 | here\n﹦try doing it better next time?".to_string(), out);
|
||||
assert_eq!("Error[oops::my::bad]: oops!\n\n[bad_file.rs] This is the part that broke:\n\n 1 | source\n 2 | text\n ⫶ | ^^^^ this bit here\n 3 | here\n\n﹦try doing it better next time?\n".to_string(), out);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue