
Drop-in replacement for assert_eq/assert_ne, rendering colorful, multi-line, line-by-line diffs on test failures to highlight differences, improve readability, and simplify debugging.
This is a Kotlin Multiplatform line-by-line transliteration port of rust-pretty-assertions/rust-pretty-assertions.
Original Project: This port is based on rust-pretty-assertions/rust-pretty-assertions. All design credit and project intent belong to the upstream authors; this repository is a faithful port to Kotlin Multiplatform with no behavioural changes intended.
This is an in-progress port. The goal is feature parity with the upstream Rust crate while providing a native Kotlin Multiplatform API. Every Kotlin file carries a // port-lint: source <path> header naming its upstream Rust counterpart so the AST-distance tool can track provenance.
The text below is reproduced and lightly edited from
https://github.com/rust-pretty-assertions/rust-pretty-assertions. It is the upstream project's own description and remains under the upstream authors' authorship; links have been rewritten to absolute upstream URLs so they continue to resolve from this repository.
Overwrite assert_eq! with a drop-in replacement, adding a colorful diff.
When writing tests in Rust, you'll probably use assert_eq!(a, b) a lot.
If such a test fails, it will present all the details of a and b.
But you have to spot the differences yourself, which is not always straightforward,
like here:
Wouldn't that task be much easier with a colorful diff?
Yep — and you only need one line of code to make it happen:
use pretty_assertions::{assert_eq, assert_ne};// 1. add the `pretty_assertions` dependency to `Cargo.toml`.
// 2. insert this line at the top of each module, as needed
use pretty_assertions::{assert_eq, assert_ne};
fn main() {
#[derive(Debug, PartialEq)]
struct Foo {
lorem: &'static str,
ipsum: u32,
dolor: Result<String, String>,
}
let x = Some(Foo { lorem: "Hello World!", ipsum: 42, dolor: Ok("hey".to_string())});
let y = Some(Foo { lorem: "Hello Wrold!", ipsum: 42, dolor: Ok("hey ho!".to_string())});
assert_eq!(x, y);
}The exact output of assertions is not guaranteed to be consistent over time, and may change between minor versions. The output of this crate is designed to be read by a human. It is not suitable for exact comparison, for example in snapshot testing.
This crate adheres to semantic versioning for publically exported crate items, except the private module, which may change between any version.
Specify it as [dev-dependencies]
and it will only be used for compiling tests, examples, and benchmarks.
This way the compile time of cargo build won't be affected!
Also add #[cfg(test)] to your use statements, like this:
#[cfg(test)]
use pretty_assertions::{assert_eq, assert_ne};If you want to enforce usage of pretty_assertions macros over std, add the following to clippy.toml:
disallowed-macros = [
{ path = "std::assert_ne", reason = "use `pretty_assertions::assert_ne` instead" },
{ path = "std::assert_eq", reason = "use `pretty_assertions::assert_eq` instead" },
{ path = "std::assert_matches::assert_matches", reason = "use `pretty_assertions::assert_matches` instead" },
]Rust 2018 edition, you need to declare
use pretty_assertions::{assert_eq, assert_ne}; per module.
Before you would write #[macro_use] extern crate pretty_assertions;.assert_ne is also switched to multi-line presentation, but does not show
a diff.For no_std support, disable the std feature and enable the alloc feature:
# Cargo.toml
pretty_assertions = { version= "...", default-features = false, features = ["alloc"] }Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
dependencies {
implementation("io.github.kotlinmania:pretty-assertions-kotlin:0.1.0")
}./gradlew build
./gradlew testSee AGENTS.md and CLAUDE.md for translator discipline, port-lint header convention, and Rust → Kotlin idiom mapping.
This Kotlin port is distributed under the same MIT license as the upstream rust-pretty-assertions/rust-pretty-assertions. See LICENSE (and any sibling LICENSE-* / NOTICE files mirrored from upstream) for the full text.
Original work copyrighted by the rust-pretty-assertions authors.
Kotlin port: Copyright (c) 2026 Sydney Renee and The Solace Project.
Thanks to the rust-pretty-assertions/rust-pretty-assertions maintainers and contributors for the original Rust implementation. This port reproduces their work in Kotlin Multiplatform; bug reports about upstream design or behavior should go to the upstream repository.
This is a Kotlin Multiplatform line-by-line transliteration port of rust-pretty-assertions/rust-pretty-assertions.
Original Project: This port is based on rust-pretty-assertions/rust-pretty-assertions. All design credit and project intent belong to the upstream authors; this repository is a faithful port to Kotlin Multiplatform with no behavioural changes intended.
This is an in-progress port. The goal is feature parity with the upstream Rust crate while providing a native Kotlin Multiplatform API. Every Kotlin file carries a // port-lint: source <path> header naming its upstream Rust counterpart so the AST-distance tool can track provenance.
The text below is reproduced and lightly edited from
https://github.com/rust-pretty-assertions/rust-pretty-assertions. It is the upstream project's own description and remains under the upstream authors' authorship; links have been rewritten to absolute upstream URLs so they continue to resolve from this repository.
Overwrite assert_eq! with a drop-in replacement, adding a colorful diff.
When writing tests in Rust, you'll probably use assert_eq!(a, b) a lot.
If such a test fails, it will present all the details of a and b.
But you have to spot the differences yourself, which is not always straightforward,
like here:
Wouldn't that task be much easier with a colorful diff?
Yep — and you only need one line of code to make it happen:
use pretty_assertions::{assert_eq, assert_ne};// 1. add the `pretty_assertions` dependency to `Cargo.toml`.
// 2. insert this line at the top of each module, as needed
use pretty_assertions::{assert_eq, assert_ne};
fn main() {
#[derive(Debug, PartialEq)]
struct Foo {
lorem: &'static str,
ipsum: u32,
dolor: Result<String, String>,
}
let x = Some(Foo { lorem: "Hello World!", ipsum: 42, dolor: Ok("hey".to_string())});
let y = Some(Foo { lorem: "Hello Wrold!", ipsum: 42, dolor: Ok("hey ho!".to_string())});
assert_eq!(x, y);
}The exact output of assertions is not guaranteed to be consistent over time, and may change between minor versions. The output of this crate is designed to be read by a human. It is not suitable for exact comparison, for example in snapshot testing.
This crate adheres to semantic versioning for publically exported crate items, except the private module, which may change between any version.
Specify it as [dev-dependencies]
and it will only be used for compiling tests, examples, and benchmarks.
This way the compile time of cargo build won't be affected!
Also add #[cfg(test)] to your use statements, like this:
#[cfg(test)]
use pretty_assertions::{assert_eq, assert_ne};If you want to enforce usage of pretty_assertions macros over std, add the following to clippy.toml:
disallowed-macros = [
{ path = "std::assert_ne", reason = "use `pretty_assertions::assert_ne` instead" },
{ path = "std::assert_eq", reason = "use `pretty_assertions::assert_eq` instead" },
{ path = "std::assert_matches::assert_matches", reason = "use `pretty_assertions::assert_matches` instead" },
]Rust 2018 edition, you need to declare
use pretty_assertions::{assert_eq, assert_ne}; per module.
Before you would write #[macro_use] extern crate pretty_assertions;.assert_ne is also switched to multi-line presentation, but does not show
a diff.For no_std support, disable the std feature and enable the alloc feature:
# Cargo.toml
pretty_assertions = { version= "...", default-features = false, features = ["alloc"] }Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
dependencies {
implementation("io.github.kotlinmania:pretty-assertions-kotlin:0.1.0")
}./gradlew build
./gradlew testSee AGENTS.md and CLAUDE.md for translator discipline, port-lint header convention, and Rust → Kotlin idiom mapping.
This Kotlin port is distributed under the same MIT license as the upstream rust-pretty-assertions/rust-pretty-assertions. See LICENSE (and any sibling LICENSE-* / NOTICE files mirrored from upstream) for the full text.
Original work copyrighted by the rust-pretty-assertions authors.
Kotlin port: Copyright (c) 2026 Sydney Renee and The Solace Project.
Thanks to the rust-pretty-assertions/rust-pretty-assertions maintainers and contributors for the original Rust implementation. This port reproduces their work in Kotlin Multiplatform; bug reports about upstream design or behavior should go to the upstream repository.