mirror of https://github.com/zkat/miette.git
fix(tests): updating tests
This commit is contained in:
parent
3584dc600c
commit
60bdf47e29
20
README.md
20
README.md
|
|
@ -10,7 +10,7 @@ protocols that allow you to hook into its error reporting facilities, and even
|
||||||
write your own error reports! It lets you define error types that can print out
|
write your own error reports! It lets you define error types that can print out
|
||||||
like this (or in any format you like!):
|
like this (or in any format you like!):
|
||||||
|
|
||||||
```sh
|
```console
|
||||||
Error: Error[oops::my::bad]: oops it broke!
|
Error: Error[oops::my::bad]: oops it broke!
|
||||||
|
|
||||||
[bad_file.rs] This is the part that broke:
|
[bad_file.rs] This is the part that broke:
|
||||||
|
|
@ -70,16 +70,12 @@ impl Diagnostic for MyBad {
|
||||||
&"oops::my::bad"
|
&"oops::my::bad"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn severity(&self) -> Severity {
|
fn help(&self) -> Option<&(dyn std::fmt::Display)> {
|
||||||
Severity::Error
|
Some(&"try doing it better next time?")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn help(&self) -> Option<Box<dyn '_ + Iterator<Item = &'_ str>>> {
|
fn snippets(&self) -> Option<Box<dyn Iterator<Item = DiagnosticSnippet>>> {
|
||||||
Some(Box::new(vec!["try doing it better next time?"].into_iter()))
|
Some(Box::new(self.snippets.clone().into_iter()))
|
||||||
}
|
|
||||||
|
|
||||||
fn snippets(&self) -> Option<&[DiagnosticSnippet]> {
|
|
||||||
Some(&self.snippets)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,11 +102,13 @@ impl fmt::Debug for MyBad {
|
||||||
/*
|
/*
|
||||||
Now we can use `miette`~
|
Now we can use `miette`~
|
||||||
*/
|
*/
|
||||||
|
use std::sync::Arc;
|
||||||
use miette::{MietteError, SourceSpan};
|
use miette::{MietteError, SourceSpan};
|
||||||
|
|
||||||
fn make_my_error() -> MyBad {
|
fn make_my_error() -> MyBad {
|
||||||
// You can use plain strings as a `Source`, bu the protocol is fully extensible!
|
// You can use plain strings as a `Source`, bu the protocol is fully extensible!
|
||||||
let src = "source\n text\n here".to_string();
|
let src = "source\n text\n here".to_string();
|
||||||
|
let len = src.len();
|
||||||
|
|
||||||
// The Rust runtime will use `{:?}` (Debug) to print any error you return
|
// The Rust runtime will use `{:?}` (Debug) to print any error you return
|
||||||
// from `main`!
|
// from `main`!
|
||||||
|
|
@ -125,10 +123,10 @@ fn make_my_error() -> MyBad {
|
||||||
snippets: vec![DiagnosticSnippet {
|
snippets: vec![DiagnosticSnippet {
|
||||||
message: Some("This is the part that broke".into()),
|
message: Some("This is the part that broke".into()),
|
||||||
source_name: "bad_file.rs".into(),
|
source_name: "bad_file.rs".into(),
|
||||||
source: Box::new(src.clone()),
|
source: Arc::new(src),
|
||||||
context: SourceSpan {
|
context: SourceSpan {
|
||||||
start: 0.into(),
|
start: 0.into(),
|
||||||
end: (src.len() - 1).into(),
|
end: (len - 1).into(),
|
||||||
},
|
},
|
||||||
highlights: Some(vec![
|
highlights: Some(vec![
|
||||||
("this bit here".into(), SourceSpan {
|
("this bit here".into(), SourceSpan {
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ fn basic() -> Result<(), MietteError> {
|
||||||
};
|
};
|
||||||
let out = format!("{:?}", err);
|
let out = format!("{:?}", err);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"Error[oops::my::bad]: oops!\n\n﹦try doing it better next time?\n".to_string(),
|
"Error[oops::my::bad]: oops!\n﹦try doing it better next time?\n".to_string(),
|
||||||
out
|
out
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -69,6 +69,6 @@ fn fancy() -> Result<(), MietteError> {
|
||||||
};
|
};
|
||||||
let out = format!("{:?}", err);
|
let out = format!("{:?}", err);
|
||||||
// println!("{}", out);
|
// 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\n﹦try doing it better next time?\n".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﹦try doing it better next time?\n".to_string(), out);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue