• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

examples/H03-May-2022-3125

src/H03-May-2022-800524

tests/H03-May-2022-288228

.cargo-checksum.jsonH A D03-May-202289 11

.cargo_vcs_info.jsonH A D01-Jan-197074 65

Cargo.lockH A D01-Jan-19702.6 KiB10391

Cargo.tomlH A D01-Jan-19701.3 KiB4035

Cargo.toml.orig-cargoH A D29-Nov-1973981 4032

README.mdH A D29-Nov-19733.6 KiB10171

README.md

1[![Build status](https://travis-ci.org/colin-kiegel/rust-pretty-assertions.svg?branch=master)](https://travis-ci.org/colin-kiegel/rust-pretty-assertions)
2[![Latest version](https://img.shields.io/crates/v/pretty-assertions.svg)](https://crates.io/crates/pretty-assertions)
3[![All downloads](https://img.shields.io/crates/d/pretty-assertions.svg)](https://crates.io/crates/pretty-assertions)
4[![Downloads of latest version](https://img.shields.io/crates/dv/pretty-assertions.svg)](https://crates.io/crates/pretty-assertions)
5
6# Pretty Assertions
7
8When writing tests in Rust, you'll probably use `assert_eq!(a, b)` _a lot_.
9
10If such a test fails, it will present all the details of `a` and `b`.
11But you have to spot the differences yourself, which is not always straightforward,
12like here:
13
14![standard assertion](https://raw.githubusercontent.com/colin-kiegel/rust-pretty-assertions/2d2357ff56d22c51a86b2f1cfe6efcee9f5a8081/examples/standard_assertion.png)
15
16Wouldn't that task be _much_ easier with a colorful diff?
17
18![pretty assertion](https://raw.githubusercontent.com/colin-kiegel/rust-pretty-assertions/2d2357ff56d22c51a86b2f1cfe6efcee9f5a8081/examples/pretty_assertion.png)
19
20Yep — and you only need **one line of code** to make it happen:
21
22```rust,ignore
23use pretty_assertions::{assert_eq, assert_ne};
24```
25
26<details>
27<summary>Show the example behind the screenshots above.</summary>
28
29```rust,ignore
30// 1. add the `pretty_assertions` dependency to `Cargo.toml`.
31// 2. insert this line at the top of each module, as needed
32use pretty_assertions::{assert_eq, assert_ne};
33
34fn main() {
35    #[derive(Debug, PartialEq)]
36    struct Foo {
37        lorem: &'static str,
38        ipsum: u32,
39        dolor: Result<String, String>,
40    }
41
42    let x = Some(Foo { lorem: "Hello World!", ipsum: 42, dolor: Ok("hey".to_string())});
43    let y = Some(Foo { lorem: "Hello Wrold!", ipsum: 42, dolor: Ok("hey ho!".to_string())});
44
45    assert_eq!(x, y);
46}
47```
48
49</details>
50
51## Tip
52
53Specify it as [`[dev-dependencies]`](http://doc.crates.io/specifying-dependencies.html#development-dependencies)
54and it will only be used for compiling tests, examples, and benchmarks.
55This way the compile time of `cargo build` won't be affected!
56
57Also add `#[cfg(test)]` to your `use` statements, like this:
58
59```rust,ignore
60#[cfg(test)]
61use pretty_assertions::{assert_eq, assert_ne};
62```
63
64## Note
65
66- Since `Rust 2018` edition, you need to declare
67  `use pretty_assertions::{assert_eq, assert_ne};` per module.
68  Before you would write `#[macro_use] extern crate pretty_assertions;`.
69- The replacement is only effective in your own crate, not in other libraries
70  you include.
71- `assert_ne` is also switched to multi-line presentation, but does _not_ show
72  a diff.
73- Under Windows, the terminal state is modified to properly handle VT100
74  escape sequences, which may break display for certain use cases.
75- The minimum supported rust version (MSRV) is 1.35.0
76
77### `no_std` support
78
79For `no_std` support, disable the `std` feature and enable the `alloc` feature:
80
81```toml
82# Cargo.toml
83pretty_assertions = { version= "...", default-features = false, features = ["alloc"] }
84```
85
86## License
87
88Licensed under either of
89
90- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0>)
91- MIT license ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)
92
93at your option.
94
95### Contribution
96
97Unless you explicitly state otherwise, any contribution intentionally
98submitted for inclusion in the work by you, as defined in the Apache-2.0
99license, shall be dual licensed as above, without any additional terms or
100conditions.
101