Skip to content
Myr

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

4 files+44 added−36 removed

added:tests/common/mod.rs+14 added
1use anyhow::{bail, Result};2use std::io;34pub fn bail_literal() -> Result<()> {5 bail!("oh no!");6}78pub fn bail_fmt() -> Result<()> {9 bail!("{} {}!", "oh", "no");10}1112pub fn bail_error() -> Result<()> {13 bail!(io::Error::new(io::ErrorKind::Other, "oh no!"));14}
added:tests/test_downcast.rs+24 added
1mod common;23use self::common::*;4use std::io;56#[test]7fn 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
1use anyhow::{bail, ensure, Result};2use std::io;1mod common;24fn bail_literal() -> Result<()> {5 bail!("oh no!");6}3use self::common::*;4use anyhow::ensure;58fn bail_fmt() -> Result<()> {9 bail!("{} {}!", "oh", "no");10}1112fn bail_error() -> Result<()> {13 bail!(io::Error::new(io::ErrorKind::Other, "oh no!"));14}156#[test]7fn 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}1213#[test]24fn 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}4243#[test]14fn test_ensure() {15 let f = || {16 ensure!(1 + 1 == 2, "This is correct");17 Ok(())
16 unmodified lines
modified:tests/test_repr.rs+3 added-3 removed
6 unmodified lines
7use std::sync::atomic::Ordering::SeqCst;8use std::sync::Arc;910#[test]11fn size_of_error() {11fn test_error_size() {12 assert_eq!(mem::size_of::<Error>(), mem::size_of::<usize>());13}1415#[test]16fn error_autotraits() {16fn test_autotraits() {17 fn assert<E: Unpin + Send + Sync + 'static>() {}18 assert::<Error>();19}2021#[test]22fn drop_works() {22fn test_drop() {23 #[derive(Debug)]24 struct DetectDrop {25 has_dropped: Arc<AtomicBool>,26 }
24 unmodified lines