/diff-assert

Primary LanguageRustMIT LicenseMIT

diff_assert

Crates.io Docs.rs MIT License Lint Test Audit Maintenance

About this crate

We designed this crate to replace assert_eq! with more powerful assert_diff! which can show exactly what part of actual data differs from expected behaviour.

You may wonder why another crate like this. We noticed that other crates have significant issues with for example whitespaces and newlines, which brings us to this solution. It's well tested, used in dozens of thousands cases in our ecosystem, and we believe it is simply more correct.

How to use it?

The simplest example is to use assert_diff! macro:

let expected = r#"foo
bar"#;

let actual = r#"foo
foo"#;

assert_diff!(expected, actual, "Here is an optional message what has changed");

Another possibility is to use try_diff! macro if you don't want to panic. It returns nice Result<(), String> instead.

let expected = r#"foo
bar"#;

let actual = r#"foo
foo"#;

if let Err(e) = try_diff!(expected, actual, "Here is an optional message what has changed") {
    eprintln!("Oh nay, we got a difference!");
    eprintln!("{}", e);
}

Besides that, crate also contains similar macros for comparing not string slices but Debug format outputs. It is quite handy for testing intermediate outputs.

Contribution

Please if possible use .hooks/:

cp .hooks/* .git/hooks/

All issues and pull requests are welcomed :)

Recommended handy tools:

  • cargo readme - to generate README.md, use scripts/readme.sh
  • cargo fmt - to reformat workspace,
  • cargo edit - to add/remove dependencies,
  • cargo clippy - to maintain code quality,
  • cargo fix - to fix errors and warnings.