Organize test files
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Tolnay · committed by David Tolnay · parent bc446d8 · Browse files · 4 files·+44 added−36 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+44 added−36 removed
- tests:+44 added−36 removed
Provenance
- Commit
4d051e4- Tree
ba6b054- Author
David Tolnay <dtolnay@gmail.com>- Committer
David Tolnay <dtolnay@gmail.com>- Parent
bc446d8
4 files changed+44 added−36 removed
added:tests/common/mod.rs+14 added
1+use anyhow::{bail, Result};2+use std::io;3+4+pub fn bail_literal() -> Result<()> {5+ bail!("oh no!");6+}7+8+pub fn bail_fmt() -> Result<()> {9+ bail!("{} {}!", "oh", "no");10+}11+12+pub fn bail_error() -> Result<()> {13+ bail!(io::Error::new(io::ErrorKind::Other, "oh no!"));14+}added:tests/test_downcast.rs+24 added
1+mod common;2+3+use self::common::*;4+use std::io;5+6+#[test]7+fn test_downcast() {8+ assert_eq!(9+ "oh no!",10+ bail_literal().unwrap_err().downcast::<&str>().unwrap(),11+ );12+ assert_eq!(13+ "oh no!",14+ bail_fmt().unwrap_err().downcast::<String>().unwrap(),15+ );16+ assert_eq!(17+ "oh no!",18+ bail_error()19+ .unwrap_err()20+ .downcast::<io::Error>()21+ .unwrap()22+ .to_string(),23+ );24+}modified:tests/test_macros.rs+3 added-33 removed
1-use anyhow::{bail, ensure, Result};2-use std::io;1+mod common;2 4-fn bail_literal() -> Result<()> {5- bail!("oh no!");6-}3+use self::common::*;4+use anyhow::ensure;5 8-fn bail_fmt() -> Result<()> {9- bail!("{} {}!", "oh", "no");10-}11-12-fn bail_error() -> Result<()> {13- bail!(io::Error::new(io::ErrorKind::Other, "oh no!"));14-}15-6 #[test]7 fn test_messages() {8 assert_eq!("oh no!", bail_literal().unwrap_err().to_string());9 assert_eq!("oh no!", bail_fmt().unwrap_err().to_string());10 assert_eq!("oh no!", bail_error().unwrap_err().to_string());11 }12 13 #[test]24-fn test_downcast() {25- assert_eq!(26- "oh no!",27- bail_literal().unwrap_err().downcast::<&str>().unwrap(),28- );29- assert_eq!(30- "oh no!",31- bail_fmt().unwrap_err().downcast::<String>().unwrap(),32- );33- assert_eq!(34- "oh no!",35- bail_error()36- .unwrap_err()37- .downcast::<io::Error>()38- .unwrap()39- .to_string(),40- );41-}42-43-#[test]14 fn test_ensure() {15 let f = || {16 ensure!(1 + 1 == 2, "This is correct");17 Ok(())16 unmodified linesmodified:tests/test_repr.rs+3 added-3 removed
6 unmodified lines7 use std::sync::atomic::Ordering::SeqCst;8 use std::sync::Arc;9 10 #[test]11-fn size_of_error() {11+fn test_error_size() {12 assert_eq!(mem::size_of::<Error>(), mem::size_of::<usize>());13 }14 15 #[test]16-fn error_autotraits() {16+fn test_autotraits() {17 fn assert<E: Unpin + Send + Sync + 'static>() {}18 assert::<Error>();19 }20 21 #[test]22-fn drop_works() {22+fn test_drop() {23 #[derive(Debug)]24 struct DetectDrop {25 has_dropped: Arc<AtomicBool>,26 }24 unmodified lines