From 935eb658cf33ca4509e0618f27bebee61b199d30 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Wed, 3 Jun 2020 14:41:42 +0200 Subject: [PATCH] make test pass with --all-features --- src/lib.rs | 3 +++ tests/test_iter.rs | 28 +++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index e0bd397..817dde2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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#" diff --git a/tests/test_iter.rs b/tests/test_iter.rs index 488ed0b..ce100d2 100644 --- a/tests/test_iter.rs +++ b/tests/test_iter.rs @@ -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> { + 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> { Ok(()) } +#[cfg(feature = "display-cause")] +#[test] +fn test_iter() -> Result<(), Box> { + 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::) + .next(); + + assert_eq!(io_error.unwrap().kind(), io::ErrorKind::NotFound); + + Ok(()) +} + #[test] fn test_find_cause() -> Result<(), Box> { let err = io::Error::from(io::ErrorKind::NotFound);