diff options
author | Aleksey Kladov <[email protected]> | 2018-08-25 12:26:34 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-25 12:26:34 +0100 |
commit | 2d41bc3e6c1adb8abce5c796cfd24f77fee6f420 (patch) | |
tree | e3b683b98ca0720d42ae55565741bd0ef806f631 /crates/test_utils | |
parent | e4828124238c4238a7f5532621d1f2df2170e77a (diff) |
rename
Diffstat (limited to 'crates/test_utils')
-rw-r--r-- | crates/test_utils/Cargo.toml | 8 | ||||
-rw-r--r-- | crates/test_utils/src/lib.rs | 36 |
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] | ||
2 | name = "test_utils" | ||
3 | version = "0.1.0" | ||
4 | authors = ["Aleksey Kladov <[email protected]>"] | ||
5 | |||
6 | [dependencies] | ||
7 | difference = "2.0.0" | ||
8 | itertools = "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 @@ | |||
1 | extern crate difference; | ||
2 | extern crate itertools; | ||
3 | |||
4 | use std::fmt; | ||
5 | use itertools::Itertools; | ||
6 | |||
7 | pub use self::difference::Changeset as __Changeset; | ||
8 | |||
9 | #[macro_export] | ||
10 | macro_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 | |||
32 | pub 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 | } | ||