# google/go-cmp

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/google-go-cmp).**

4,651 stars · 224 forks · Go · BSD-3-Clause

## Links

- GitHub: https://github.com/google/go-cmp
- awesome-repositories: https://awesome-repositories.com/repository/google-go-cmp.md

## Topics

`equality` `go` `testing`

## Description

go-cmp is a value comparison library for Go designed for use in test suites. It functions as a recursive data differ and assertion tool that determines if two complex data structures are semantically equal rather than relying on strict bitwise equality.

The library provides a framework for defining specialized comparison logic, allowing users to register custom equality overrides for specific types. It includes mechanisms to manage how unexported fields are handled during traversal to prevent runtime panics during deep equality checks.

The system utilizes reflection-based value traversal to identify specific mismatches between expected and actual values, producing detailed differences when values do not match. It supports type-specific equality dispatch and configurable comparison behavior.

## Tags

### Software Engineering & Architecture

- [Recursive Semantic Equality](https://awesome-repositories.com/f/software-engineering-architecture/recursive-semantic-equality.md) — Determines if two complex data structures are semantically equal by recursively comparing their components.
- [Comparison Logic Overrides](https://awesome-repositories.com/f/software-engineering-architecture/comparison-logic-overrides.md) — Provides a framework for registering custom functions to replace default equality logic for specific types.
- [Custom Equality Definitions](https://awesome-repositories.com/f/software-engineering-architecture/custom-equality-definitions.md) — Allows the definition of custom comparison functions to handle special cases like floating-point tolerances. ([source](https://cdn.jsdelivr.net/gh/google/go-cmp@master/README.md))
- [Recursive Data Diffing](https://awesome-repositories.com/f/software-engineering-architecture/recursive-data-diffing.md) — Traverses Go types recursively to identify and produce detailed mismatches between expected and actual values.
- [Semantic Value Comparison](https://awesome-repositories.com/f/software-engineering-architecture/semantic-value-comparison.md) — Determines if two values are semantically equal by recursively comparing primitive types or applying specialized logic. ([source](https://cdn.jsdelivr.net/gh/google/go-cmp@master/README.md))
- [Special Type Equality Handlers](https://awesome-repositories.com/f/software-engineering-architecture/custom-equality-definitions/special-type-equality-handlers.md) — Routes comparison logic to special handlers based on the concrete type of the values.
- [Functional Options](https://awesome-repositories.com/f/software-engineering-architecture/functional-design-patterns/functional-options.md) — Implements the functional options pattern to configure complex comparison settings via variadic functions.

### Data & Databases

- [Reflection-Based Comparison](https://awesome-repositories.com/f/data-databases/value-comparators/reflection-based-comparison.md) — Uses Go reflection to recursively walk through complex data structures for deep equality checks.

### Programming Languages & Runtimes

- [Equality Logic Frameworks](https://awesome-repositories.com/f/programming-languages-runtimes/programming-utilities/data-structure-type-helpers/data-structure-utilities/deep-equality-checking/equality-logic-frameworks.md) — Provides a configurable framework for implementing specialized comparison logic and handling unexported fields.
- [Unexported Field Access Control](https://awesome-repositories.com/f/programming-languages-runtimes/unexported-field-access-control.md) — Manages reflection access to unexported fields to prevent runtime panics during deep equality checks.
- [Object Equality Implementations](https://awesome-repositories.com/f/programming-languages-runtimes/object-equality-implementations.md) — Supports defining specific equality methods on types to control how their equality is calculated. ([source](https://cdn.jsdelivr.net/gh/google/go-cmp@master/README.md))

### Testing & Quality Assurance

- [Go Testing Frameworks](https://awesome-repositories.com/f/testing-quality-assurance/go-testing-frameworks.md) — Serves as a specialized assertion tool for Go that generates detailed diffs between expected and actual values.
- [Private Field Comparison Controls](https://awesome-repositories.com/f/testing-quality-assurance/private-field-comparison-controls.md) — Provides capabilities to manage whether unexported fields are included in value comparisons during testing. ([source](https://cdn.jsdelivr.net/gh/google/go-cmp@master/README.md))
- [Unexported Field Handling](https://awesome-repositories.com/f/testing-quality-assurance/unexported-field-handling.md) — Manages how private struct fields are treated during comparison to prevent panics in Go test suites.
- [Value Comparison Libraries](https://awesome-repositories.com/f/testing-quality-assurance/value-comparison-libraries.md) — Compares complex Go data structures in tests using semantic equality instead of strict bitwise equality.
- [Custom Assertions](https://awesome-repositories.com/f/testing-quality-assurance/custom-assertions.md) — Enables specialized equality rules for types to handle business logic or floating point precision during verification.
- [Unit Testing](https://awesome-repositories.com/f/testing-quality-assurance/software-testing/testing-frameworks/unit/unit-testing.md) — Facilitates the verification of complex data structures within Go unit tests.

### Part of an Awesome List

- [Testing and QA](https://awesome-repositories.com/f/awesome-lists/devtools/testing-and-qa.md) — Package for comparing Go values in tests.
- [Testing and Quality Assurance](https://awesome-repositories.com/f/awesome-lists/devtools/testing-and-quality-assurance.md) — Package for deep comparison of Go values.
- [Testing Frameworks](https://awesome-repositories.com/f/awesome-lists/devtools/testing-frameworks.md) — Package for comparing Go values in tests.
