-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(protocol): add StdError impl for Box<dyn Diagnostic + Send + Syn…
…c> (#273)
- Loading branch information
1 parent
8980675
commit 2e3e5c9
Showing
2 changed files
with
87 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use std::sync::Arc; | ||
|
||
use miette::{miette, Diagnostic}; | ||
use thiserror::Error; | ||
|
||
#[test] | ||
fn test_source() { | ||
#[derive(Debug, Diagnostic, Error)] | ||
#[error("Bar")] | ||
struct Bar; | ||
|
||
#[derive(Debug, Diagnostic, Error)] | ||
#[error("Foo")] | ||
struct Foo { | ||
#[source] | ||
bar: Bar, | ||
} | ||
|
||
let e = miette!(Foo { bar: Bar }); | ||
let mut chain = e.chain(); | ||
|
||
assert_eq!("Foo", chain.next().unwrap().to_string()); | ||
assert_eq!("Bar", chain.next().unwrap().to_string()); | ||
assert!(chain.next().is_none()); | ||
} | ||
|
||
#[test] | ||
fn test_source_boxed() { | ||
#[derive(Debug, Diagnostic, Error)] | ||
#[error("Bar")] | ||
struct Bar; | ||
|
||
#[derive(Debug, Diagnostic, Error)] | ||
#[error("Foo")] | ||
struct Foo { | ||
#[source] | ||
bar: Box<dyn Diagnostic + Send + Sync>, | ||
} | ||
|
||
let error = miette!(Foo { bar: Box::new(Bar) }); | ||
|
||
let mut chain = error.chain(); | ||
|
||
assert_eq!("Foo", chain.next().unwrap().to_string()); | ||
assert_eq!("Bar", chain.next().unwrap().to_string()); | ||
assert!(chain.next().is_none()); | ||
} | ||
|
||
#[test] | ||
fn test_source_arc() { | ||
#[derive(Debug, Diagnostic, Error)] | ||
#[error("Bar")] | ||
struct Bar; | ||
|
||
#[derive(Debug, Diagnostic, Error)] | ||
#[error("Foo")] | ||
struct Foo { | ||
#[source] | ||
bar: Arc<dyn Diagnostic + Send + Sync>, | ||
} | ||
|
||
let error = miette!(Foo { bar: Arc::new(Bar) }); | ||
|
||
let mut chain = error.chain(); | ||
|
||
assert_eq!("Foo", chain.next().unwrap().to_string()); | ||
assert_eq!("Bar", chain.next().unwrap().to_string()); | ||
assert!(chain.next().is_none()); | ||
} |