Skip to content

Commit 38af3e0

Browse files
Add tiny crate for better predicate assertions
1 parent cac729f commit 38af3e0

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

testutils/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Cargo.lock
2+
target/

testutils/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "testutils"
3+
version = "0.1.0"
4+
authors = ["Ian Chamberlain <[email protected]>"]
5+
edition = "2018"
6+
7+
[dependencies]
8+
predicates = "1.0.2"
9+
predicates-tree = "1.0.0"

testutils/src/lib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/// Simple macro to panic with a prettier error message
2+
/// # Examples
3+
/// ```
4+
/// use predicates::prelude::*;
5+
/// use testutils::assert_that;
6+
///
7+
/// assert_that!(
8+
/// "Hello World",
9+
/// predicates::str::similar("Hello World"),
10+
/// );
11+
/// assert_that!(
12+
/// "Hello world",
13+
/// predicates::str::diff("Goodbye world"),
14+
/// );
15+
/// ```
16+
#[macro_export]
17+
macro_rules! assert_that {
18+
($item:expr, $pred:expr $(,)?) => {{
19+
use ::predicates::prelude::*;
20+
use ::predicates_tree::CaseTreeExt;
21+
22+
if let Some(case) = $pred.find_case(false, $item) {
23+
panic!("{}", case.tree());
24+
};
25+
}};
26+
}

0 commit comments

Comments
 (0)