Skip to content

Commit

Permalink
fix(tests): updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Aug 8, 2021
1 parent 3584dc6 commit 60bdf47
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
20 changes: 9 additions & 11 deletions README.md
Expand Up @@ -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
like this (or in any format you like!):

```sh
```console
Error: Error[oops::my::bad]: oops it broke!

[bad_file.rs] This is the part that broke:
Expand Down Expand Up @@ -70,16 +70,12 @@ impl Diagnostic for MyBad {
&"oops::my::bad"
}

fn severity(&self) -> Severity {
Severity::Error
}

fn help(&self) -> Option<Box<dyn '_ + Iterator<Item = &'_ str>>> {
Some(Box::new(vec!["try doing it better next time?"].into_iter()))
fn help(&self) -> Option<&(dyn std::fmt::Display)> {
Some(&"try doing it better next time?")
}

fn snippets(&self) -> Option<&[DiagnosticSnippet]> {
Some(&self.snippets)
fn snippets(&self) -> Option<Box<dyn Iterator<Item = DiagnosticSnippet>>> {
Some(Box::new(self.snippets.clone().into_iter()))
}
}

Expand All @@ -106,11 +102,13 @@ impl fmt::Debug for MyBad {
/*
Now we can use `miette`~
*/
use std::sync::Arc;
use miette::{MietteError, SourceSpan};

fn make_my_error() -> MyBad {
// You can use plain strings as a `Source`, bu the protocol is fully extensible!
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
// from `main`!
Expand All @@ -125,10 +123,10 @@ fn make_my_error() -> MyBad {
snippets: vec![DiagnosticSnippet {
message: Some("This is the part that broke".into()),
source_name: "bad_file.rs".into(),
source: Box::new(src.clone()),
source: Arc::new(src),
context: SourceSpan {
start: 0.into(),
end: (src.len() - 1).into(),
end: (len - 1).into(),
},
highlights: Some(vec![
("this bit here".into(), SourceSpan {
Expand Down
4 changes: 2 additions & 2 deletions tests/reporter.rs
Expand Up @@ -39,7 +39,7 @@ fn basic() -> Result<(), MietteError> {
};
let out = format!("{:?}", err);
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
);
Ok(())
Expand Down Expand Up @@ -69,6 +69,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\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(())
}

0 comments on commit 60bdf47

Please sign in to comment.