From 0e6ea5debc7aee5d1b43865482a76c2ee0ad3513 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Fri, 30 Aug 2019 18:23:01 +0900 Subject: [PATCH] Separate tests into tests/error.rs --- src/liballoc/error.rs | 45 ------------------------------------- src/liballoc/tests/error.rs | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 45 deletions(-) create mode 100644 src/liballoc/tests/error.rs diff --git a/src/liballoc/error.rs b/src/liballoc/error.rs index d78290ce976d5..0a436d5e42cc3 100644 --- a/src/liballoc/error.rs +++ b/src/liballoc/error.rs @@ -888,48 +888,3 @@ impl dyn Error + Send + Sync { }) } } - -#[cfg(test)] -mod tests { - use super::Error; - use core::fmt; - - #[derive(Debug, PartialEq)] - struct A; - #[derive(Debug, PartialEq)] - struct B; - - impl fmt::Display for A { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "A") - } - } - impl fmt::Display for B { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "B") - } - } - - impl Error for A { - fn description(&self) -> &str { "A-desc" } - } - impl Error for B { - fn description(&self) -> &str { "A-desc" } - } - - #[test] - fn downcasting() { - let mut a = A; - let a = &mut a as &mut (dyn Error + 'static); - assert_eq!(a.downcast_ref::(), Some(&A)); - assert_eq!(a.downcast_ref::(), None); - assert_eq!(a.downcast_mut::(), Some(&mut A)); - assert_eq!(a.downcast_mut::(), None); - - let a: Box = Box::new(A); - match a.downcast::() { - Ok(..) => panic!("expected error"), - Err(e) => assert_eq!(*e.downcast::().unwrap(), A), - } - } -} diff --git a/src/liballoc/tests/error.rs b/src/liballoc/tests/error.rs new file mode 100644 index 0000000000000..0cf73f2cf0075 --- /dev/null +++ b/src/liballoc/tests/error.rs @@ -0,0 +1,41 @@ +use std::error::Error; +use std::fmt; + +#[derive(Debug, PartialEq)] +struct A; +#[derive(Debug, PartialEq)] +struct B; + +impl fmt::Display for A { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "A") + } +} +impl fmt::Display for B { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "B") + } +} + +impl Error for A { + fn description(&self) -> &str { "A-desc" } +} +impl Error for B { + fn description(&self) -> &str { "A-desc" } +} + +#[test] +fn downcasting() { + let mut a = A; + let a = &mut a as &mut (dyn Error + 'static); + assert_eq!(a.downcast_ref::(), Some(&A)); + assert_eq!(a.downcast_ref::(), None); + assert_eq!(a.downcast_mut::(), Some(&mut A)); + assert_eq!(a.downcast_mut::(), None); + + let a: Box = Box::new(A); + match a.downcast::() { + Ok(..) => panic!("expected error"), + Err(e) => assert_eq!(*e.downcast::().unwrap(), A), + } +}