Skip to content

Commit 1d269d3

Browse files
authored
Merge pull request #495 from Aaron1011/feature/pretty-test
Use `pretty_assertions` crate when comparing expected and actual output
2 parents c1ec2d3 + 036a336 commit 1d269d3

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

Cargo.lock

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ chalk-parse = { version = "0.12.0-dev.0", path = "chalk-parse" }
2929
chalk-integration = { version = "0.12.0-dev.0", path = "chalk-integration" }
3030

3131
[workspace]
32+
33+
[dev-dependencies]
34+
pretty_assertions = "0.6.1"

tests/test_util.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,11 @@ pub fn assert_same(result: &str, expected: &str) {
4040

4141
let expected1: String = expected.chars().filter(|w| !w.is_whitespace()).collect();
4242
let result1: String = result.chars().filter(|w| !w.is_whitespace()).collect();
43-
assert!(!expected1.is_empty() && result1.starts_with(&expected1));
43+
assert!(!expected1.is_empty(), "Expectation cannot be empty!");
44+
if !result1.starts_with(&expected1) {
45+
let prefix = &result1[..std::cmp::min(result1.len(), expected1.len())];
46+
// These will never be equal, which will cause a nice error message
47+
// to be displayed
48+
pretty_assertions::assert_eq!(expected1, prefix);
49+
}
4450
}

0 commit comments

Comments
 (0)