diff --git a/cmp/cmpopts/equate.go b/cmp/cmpopts/equate.go index 51ce36f..e4ffca8 100644 --- a/cmp/cmpopts/equate.go +++ b/cmp/cmpopts/equate.go @@ -11,7 +11,6 @@ import ( "time" "github.com/google/go-cmp/cmp" - "golang.org/x/xerrors" ) func equateAlways(_, _ interface{}) bool { return true } @@ -147,10 +146,3 @@ func areConcreteErrors(x, y interface{}) bool { _, ok2 := y.(error) return ok1 && ok2 } - -func compareErrors(x, y interface{}) bool { - xe := x.(error) - ye := y.(error) - // TODO(≥go1.13): Use standard definition of errors.Is. - return xerrors.Is(xe, ye) || xerrors.Is(ye, xe) -} diff --git a/cmp/cmpopts/errors_go113.go b/cmp/cmpopts/errors_go113.go new file mode 100644 index 0000000..5a7b18a --- /dev/null +++ b/cmp/cmpopts/errors_go113.go @@ -0,0 +1,16 @@ +// Copyright 2021, The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build go1.13 + +package cmpopts + +import "errors" + +func compareErrors(x, y interface{}) bool { + xe := x.(error) + ye := y.(error) + // Use standard definition of errors.Is with ≥go1.13. + return errors.Is(xe, ye) || errors.Is(ye, xe) +} diff --git a/cmp/cmpopts/errors_xerrors.go b/cmp/cmpopts/errors_xerrors.go new file mode 100644 index 0000000..ae46944 --- /dev/null +++ b/cmp/cmpopts/errors_xerrors.go @@ -0,0 +1,16 @@ +// Copyright 2021, The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build !go1.13 + +package cmpopts + +import "golang.org/x/xerrors" + +func compareErrors(x, y interface{}) bool { + xe := x.(error) + ye := y.(error) + // Use xerrors with