Skip to content
Myr

Move macro tests to tests directory

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 541b275 · Browse files · 2 files+23 added−46 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+23 added−46 removed

  • tests:+23 added−1 removed
  • other:+0 added−45 removed

2 files+23 added−46 removed

modified:src/lib.rs-45 removed
415 unmodified lines
416417 Error::new_adhoc(message, backtrace)418 }419}420421#[cfg(test)]422mod test {423 use super::*;424425 #[test]426 fn anyhow() {427 let error1 = anyhow!("This {}", "works");428 let error2 = anyhow!("This works");429 assert_eq!(error1.to_string(), error2.to_string());430 }431432 #[test]433 fn bail() {434 let f = || -> Result<()> { bail!("This {}", "works") };435 let error1 = f().err().unwrap();436437 let f = || -> Result<()> { bail!("This works") };438 let error2 = f().err().unwrap();439440 assert_eq!(error1.to_string(), error2.to_string());441 }442443 #[test]444 fn ensure() {445 let f = || {446 ensure!(1 + 1 == 2, "This is correct");447 Ok(())448 };449 assert!(f().is_ok());450451 let v = 1;452 let f = || {453 ensure!(v + v == 2, "This is correct, v: {}", v);454 Ok(())455 };456 assert!(f().is_ok());457458 let f = || {459 ensure!(v + v == 1, "This is not correct, v: {}", v);460 Ok(())461 };462 assert!(f().is_err());463 }464}
modified:tests/macros.rs+23 added-1 removed
1use anyhow::{bail, Result};1use anyhow::{bail, ensure, Result};2use std::io;34fn bail_literal() -> Result<()> {5 bail!("oh no!");
19 unmodified lines
25 assert_eq!("oh no!", bail_literal().unwrap_err().downcast::<&str>().unwrap());26 assert_eq!("oh no!", bail_fmt().unwrap_err().downcast::<String>().unwrap());27 assert_eq!("oh no!", bail_error().unwrap_err().downcast::<io::Error>().unwrap().to_string());28}2930#[test]31fn test_ensure() {32 let f = || {33 ensure!(1 + 1 == 2, "This is correct");34 Ok(())35 };36 assert!(f().is_ok());3738 let v = 1;39 let f = || {40 ensure!(v + v == 2, "This is correct, v: {}", v);41 Ok(())42 };43 assert!(f().is_ok());4445 let f = || {46 ensure!(v + v == 1, "This is not correct, v: {}", v);47 Ok(())48 };49 assert!(f().is_err());50}