aboutsummaryrefslogtreecommitdiff
path: root/crates/test_utils
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-25 12:26:34 +0100
committerAleksey Kladov <[email protected]>2018-08-25 12:26:34 +0100
commit2d41bc3e6c1adb8abce5c796cfd24f77fee6f420 (patch)
treee3b683b98ca0720d42ae55565741bd0ef806f631 /crates/test_utils
parente4828124238c4238a7f5532621d1f2df2170e77a (diff)
rename
Diffstat (limited to 'crates/test_utils')
-rw-r--r--crates/test_utils/Cargo.toml8
-rw-r--r--crates/test_utils/src/lib.rs36
2 files changed, 44 insertions, 0 deletions
diff --git a/crates/test_utils/Cargo.toml b/crates/test_utils/Cargo.toml
new file mode 100644
index 000000000..3d336a9b4
--- /dev/null
+++ b/crates/test_utils/Cargo.toml
@@ -0,0 +1,8 @@
1[package]
2name = "test_utils"
3version = "0.1.0"
4authors = ["Aleksey Kladov <[email protected]>"]
5
6[dependencies]
7difference = "2.0.0"
8itertools = "0.7.8"
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs
new file mode 100644
index 000000000..26b9bfb38
--- /dev/null
+++ b/crates/test_utils/src/lib.rs
@@ -0,0 +1,36 @@
1extern crate difference;
2extern crate itertools;
3
4use std::fmt;
5use itertools::Itertools;
6
7pub use self::difference::Changeset as __Changeset;
8
9#[macro_export]
10macro_rules! assert_eq_text {
11 ($expected:expr, $actual:expr) => {{
12 let expected = $expected;
13 let actual = $actual;
14 if expected != actual {
15 let changeset = $crate::__Changeset::new(actual, expected, "\n");
16 println!("Expected:\n{}\n\nActual:\n{}\nDiff:{}\n", expected, actual, changeset);
17 panic!("text differs");
18 }
19 }};
20 ($expected:expr, $actual:expr, $($tt:tt)*) => {{
21 let expected = $expected;
22 let actual = $actual;
23 if expected != actual {
24 let changeset = $crate::__Changeset::new(actual, expected, "\n");
25 println!("Expected:\n{}\n\nActual:\n{}\n\nDiff:\n{}\n", expected, actual, changeset);
26 println!($($tt)*);
27 panic!("text differs");
28 }
29 }};
30}
31
32pub fn assert_eq_dbg(expected: &str, actual: &impl fmt::Debug) {
33 let actual = format!("{:?}", actual);
34 let expected = expected.lines().map(|l| l.trim()).join(" ");
35 assert_eq!(expected, actual);
36}