Replace reflect.DeepEqual in Go tests to get a human-readable diff showing exactly what changed.
Write custom equality rules for specific types, such as treating two floating-point numbers as equal when they are very close.
Compare complex nested structs in tests without crashes on nil pointers or accidental matches on private fields.
go-cmp is a small Go library from Google for checking whether two values are equal in tests. Go is a programming language, and when you write automated tests for Go code, you often need to compare an expected result against an actual result to see if they match. The standard approach built into Go for doing this comparison has some limitations: it does not handle all data types well, it can crash on certain kinds of values, and it gives you no way to define what "equal" means for your own types. This library was written to address those problems. With go-cmp, you can compare two values and get a clear description of exactly how they differ, which makes it easier to understand a failing test. You can also provide custom rules for specific types, for example telling the library to treat two floating-point numbers as equal if they are very close to each other rather than requiring them to be identical. Types that define their own equality method will have that method respected automatically. One deliberate difference from the built-in Go comparison: go-cmp does not compare private (unexported) fields inside a type unless you explicitly allow it, which avoids a class of accidental test failures and forces you to think about what your test is actually checking. Installation is a single command using Go's standard package manager.
← google on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.