go-cmp is a package for comparing Go values in tests that provides a more powerful and safer alternative to reflect.DeepEqual.
The package addresses the limitations of Go's built-in reflect.DeepEqual by offering customizable equality semantics. It allows tests to define custom equality functions that override default behavior, enabling use cases like floating-point comparisons with tolerance thresholds. Types can implement an Equal method to control how instances of themselves are compared, giving package authors direct control over equality semantics. When no customization is applied, the tool recursively compares primitive kinds across values, but with a key safety difference: unexported fields are not compared by default and will cause panics unless explicitly handled through options like IgnoreUnexported or AllowUnexported.
Developers should adopt this package when testing Go code that requires flexible equality semantics beyond simple value comparison. It suits projects where default equality behavior is insufficient, particularly those involving floating-point arithmetic, custom types with special equality requirements, or cases where unexported field comparison needs explicit control. The tool is especially valuable for package authors who want to define equality semantics for their own types through the Equal method pattern.
The project maintains a stable, focused scope centered on the core equality comparison problem. Development activity shows consistent attention to the codebase with regular updates addressing edge cases and user-reported issues. The maintainers respond to community feedback and incorporate improvements that refine the tool's behavior without expanding its fundamental purpose.