mirror of
https://github.com/haraldh/chainerror.git
synced 2025-01-31 00:56:41 +01:00
make test pass with --all-features
This commit is contained in:
parent
241502de75
commit
935eb658cf
|
@ -49,6 +49,7 @@
|
|||
//! }
|
||||
//!
|
||||
//! if let Err(e) = func1() {
|
||||
//! # #[cfg(not(feature = "no-debug-cause"))]
|
||||
//! #[cfg(not(windows))]
|
||||
//! assert_eq!(
|
||||
//! format!("\n{:?}\n", e),
|
||||
|
@ -143,6 +144,7 @@
|
|||
//! eprintln!("\nThe root cause was: std::io::Error: {:#?}", io_error);
|
||||
//! }
|
||||
//!
|
||||
//! # #[cfg(not(feature = "no-debug-cause"))]
|
||||
//! #[cfg(not(windows))]
|
||||
//! assert_eq!(
|
||||
//! format!("\n{:?}\n", e),
|
||||
|
@ -848,6 +850,7 @@ macro_rules! cherr {
|
|||
/// }
|
||||
///
|
||||
/// # if let Err(e) = func1() {
|
||||
/// # #[cfg(not(feature = "no-debug-cause"))]
|
||||
/// # #[cfg(not(windows))]
|
||||
/// # assert_eq!(
|
||||
/// # format!("\n{:?}\n", e), r#"
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
use chainerror::*;
|
||||
use std::error::Error;
|
||||
use std::fmt::Write;
|
||||
use std::io;
|
||||
|
||||
#[cfg(not(feature = "display-cause"))]
|
||||
#[test]
|
||||
fn test_iter() -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
use std::fmt::Write;
|
||||
let err = io::Error::from(io::ErrorKind::NotFound);
|
||||
let err = cherr!(err, "1");
|
||||
let err = cherr!(err, "2");
|
||||
|
@ -30,6 +31,31 @@ fn test_iter() -> Result<(), Box<dyn Error + Send + Sync>> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "display-cause")]
|
||||
#[test]
|
||||
fn test_iter() -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
let err = io::Error::from(io::ErrorKind::NotFound);
|
||||
let err = cherr!(err, "1");
|
||||
let err = cherr!(err, "2");
|
||||
let err = cherr!(err, "3");
|
||||
let err = cherr!(err, "4");
|
||||
let err = cherr!(err, "5");
|
||||
let err = cherr!(err, "6");
|
||||
|
||||
let res = err.to_string();
|
||||
|
||||
assert_eq!(res, "6\nCaused by:\n5\nCaused by:\n4\nCaused by:\n3\nCaused by:\n2\nCaused by:\n1\nCaused by:\nentity not found");
|
||||
|
||||
let io_error: Option<&io::Error> = err
|
||||
.iter()
|
||||
.filter_map(Error::downcast_ref::<io::Error>)
|
||||
.next();
|
||||
|
||||
assert_eq!(io_error.unwrap().kind(), io::ErrorKind::NotFound);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_find_cause() -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
let err = io::Error::from(io::ErrorKind::NotFound);
|
||||
|
|
Loading…
Reference in a new issue