diff --git a/backpack/Cargo.toml b/backpack/Cargo.toml index 3e544da..2832fc2 100644 --- a/backpack/Cargo.toml +++ b/backpack/Cargo.toml @@ -14,4 +14,8 @@ path = "src/main.rs" [features] coverage = [] -[dependencies] +[dev-dependencies] +demonstrate = "*" +async-attributes = "*" +async-std = "*" +pretty_assertions = "*" diff --git a/backpack/src/lib.rs b/backpack/src/lib.rs index 73920b4..082e575 100644 --- a/backpack/src/lib.rs +++ b/backpack/src/lib.rs @@ -6,9 +6,40 @@ pub fn multiply(a: i32, b: i32) -> i32 { #[cfg(test)] mod test { use super::*; + use demonstrate::demonstrate; - #[test] - fn test() { - assert_eq!(multiply(2, 2), 4); + demonstrate! { + describe "module" { + use super::*; + + before { + let four = 4; + } + + it "can fail" { + assert_eq!(multiply(2, 2), four); + } + + test "is returnable" -> Result<(), &'static str> { + if multiply(2, 2) == four { + Ok(()) + } else { + Err("It isn't 4! :o") + } + } + + #[async_attributes::test] + async context "asynchronous" { + before { + let is_4_task = async_std::task::spawn(async { + multiply(2, 2) + }); + } + + it "awaits" { + assert_eq!(four, is_4_task.await) + } + } + } } }