commit | 3a98a11b2c6d5ad66696f2954b3811f0244fb71d | [log] [tgz] |
---|---|---|
author | Tobias Klauser <tobias.klauser@gmail.com> | Fri Feb 05 01:08:49 2021 +0100 |
committer | GitHub <noreply@github.com> | Thu Feb 04 16:08:49 2021 -0800 |
tree | 2972e86b2fa9017d82023f79485bc2026c69e2dc | |
parent | ec71d6d790538ad88c95a192fd059e11afb45b6f [diff] |
cmp/cmpopts: use errors.Is with ≥go1.13 in compareErrors (#251) Use the standard definition of errors.Is to implement compareErrors with ≥go1.13. Retain the implementation using golang.org/x/xerrors for versions <go1.13. This will allow packages using newer Go versions and already relying on the errors package to get rid of the transitive dependency on golang.org/x/xerrors.
This package is intended to be a more powerful and safer alternative to reflect.DeepEqual
for comparing whether two values are semantically equal.
The primary features of cmp
are:
When the default behavior of equality does not suit the needs of the test, custom equality functions can override the equality operation. For example, an equality function may report floats as equal so long as they are within some tolerance of each other.
Types that have an Equal
method may use that method to determine equality. This allows package authors to determine the equality operation for the types that they define.
If no custom equality functions are used and no Equal
method is defined, equality is determined by recursively comparing the primitive kinds on both values, much like reflect.DeepEqual
. Unlike reflect.DeepEqual
, unexported fields are not compared by default; they result in panics unless suppressed by using an Ignore
option (see cmpopts.IgnoreUnexported
) or explicitly compared using the AllowUnexported
option.
See the documentation for more information.
This is not an official Google product.
go get -u github.com/google/go-cmp/cmp
BSD - See LICENSE file