mirror of
https://github.com/dtolnay/thiserror.git
synced 2025-04-03 04:47:38 +03:00
Add test of transparent variant in enum with format args
error: cannot have both #[error(transparent)] and a display attribute --> tests/test_transparent.rs:51:5 | 51 | #[error("this failed: {0}_{1}")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This commit is contained in:
parent
02aaafc783
commit
71adf02435
1 changed files with 18 additions and 0 deletions
|
@ -45,6 +45,24 @@ fn test_transparent_enum() {
|
|||
assert_eq!("inner", error.source().unwrap().to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_transparent_enum_with_default_message() {
|
||||
#[derive(Error, Debug)]
|
||||
#[error("this failed: {0}_{1}")]
|
||||
enum Error {
|
||||
This(i32, i32),
|
||||
#[error(transparent)]
|
||||
Other(anyhow::Error),
|
||||
}
|
||||
|
||||
let error = Error::This(-1, -1);
|
||||
assert_eq!("this failed: -1_-1", error.to_string());
|
||||
|
||||
let error = Error::Other(anyhow!("inner").context("outer"));
|
||||
assert_eq!("outer", error.to_string());
|
||||
assert_eq!("inner", error.source().unwrap().to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_anyhow() {
|
||||
#[derive(Error, Debug)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue