Skip to content

Commit

Permalink
feat: Add BBD tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
yonas committed Nov 29, 2024
1 parent 1816504 commit a68c7be
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
6 changes: 5 additions & 1 deletion backpack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ path = "src/main.rs"
[features]
coverage = []

[dependencies]
[dev-dependencies]
demonstrate = "*"
async-attributes = "*"
async-std = "*"
pretty_assertions = "*"
37 changes: 34 additions & 3 deletions backpack/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
}

0 comments on commit a68c7be

Please sign in to comment.