A Go package for comparing values in tests with customizable equality and safer defaults than reflect.DeepEqual.
go-cmp is a Go package for comparing values in tests, offering a safer and more flexible alternative to `reflect.DeepEqual`. It solves the problem of unreliable or overly strict equality checks by allowing custom equality functions and controlled handling of unexported fields.
Go developers writing unit tests who need precise control over value comparisons, especially those working with complex data structures or custom types.
Developers choose go-cmp over `reflect.DeepEqual` for its safety features, such as avoiding panics from unexported fields, and its flexibility through customizable equality functions and support for type-defined `Equal` methods.
Package for comparing Go values in tests
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Allows overriding default equality, such as comparing floats within a tolerance, as demonstrated in the README for handling numerical precision.
Automatically uses a type's `Equal` method if present, enabling package authors to define semantic equality, as highlighted in the features.
Prevents panics by not comparing unexported fields by default, requiring explicit options like `IgnoreUnexported`, a key safety feature mentioned in the README.
Falls back to comparing primitive kinds recursively, similar to `reflect.DeepEqual` but with controlled unexported field handling for robustness.
Requires explicit options for handling unexported fields or custom comparisons, adding complexity to test setup compared to more automatic alternatives.
Only provides comparison logic without integrated test assertion helpers, necessitating extra code for error reporting and test integration.
The recursive comparison and custom function evaluations can be slower than simple equality checks, potentially slowing down large test suites.