package cmp
Import Path
gotest.tools/v3/assert/cmp (on go.dev)
Dependency Relation
imports 11 packages, and imported by 2 packages
Package-Level Type Names (total 6, in which 4 are exported)
Comparison is a function which compares values and returns ResultSuccess if
the actual value matches the expected value. If the values do not match the
Result will contain a message about why it failed.
func Contains(collection interface{}, item interface{}) Comparison
func DeepEqual(x, y interface{}, opts ...cmp.Option) Comparison
func Equal(x, y interface{}) Comparison
func Error(err error, message string) Comparison
func ErrorContains(err error, substring string) Comparison
func ErrorIs(actual error, expected error) Comparison
func ErrorType(err error, expected interface{}) Comparison
func Len(seq interface{}, expected int) Comparison
func Nil(obj interface{}) Comparison
func Panics(f func()) Comparison
func Regexp(re RegexOrPattern, v string) Comparison
func isNil(obj interface{}, msgFunc func(reflect.Value) string) Comparison
func gotest.tools/v3/internal/assert.RunComparison(t assert.LogT, argSelector assert.argSelector, f Comparison, msgAndArgs ...interface{}) bool
RegexOrPattern may be either a *regexp.Regexp or a string that is a valid
regexp pattern.
func Regexp(re RegexOrPattern, v string) Comparison
A Result of a Comparison.
( Result) Success() bool
StringResult
*os.ProcessState
os/exec.ExitError
templatedResult
func ResultFailureTemplate(template string, data map[string]interface{}) Result
func ResultFromError(err error) Result
func cmpErrorTypeEqualType(err error, expectedType reflect.Type) Result
func cmpErrorTypeFunc(err error, f func(error) bool) Result
func cmpErrorTypeImplementsType(err error, expectedType reflect.Type) Result
func multiLineDiffResult(diff string, x, y interface{}) Result
func toResult(success bool, msg string) Result
StringResult is an implementation of Result that reports the error message
string verbatim and does not provide any templating or formatting of the
message.
message string
success bool
FailureMessage returns the message used to provide additional information
about the failure.
Success returns true if the comparison was successful.
StringResult : Result
StringResult : gotest.tools/v3/internal/assert.resultBasic
func ResultFailure(message string) StringResult
var ResultSuccess
Package-Level Functions (total 26, in which 14 are exported)
Contains succeeds if item is in collection. Collection may be a string, map,
slice, or array.
If collection is a string, item must also be a string, and is compared using
strings.Contains().
If collection is a Map, contains will succeed if item is a key in the map.
If collection is a slice or array, item is compared to each item in the
sequence using reflect.DeepEqual().
DeepEqual compares two values using google/go-cmp
(https://godoc.org/github.com/google/go-cmp/cmp)
and succeeds if the values are equal.
The comparison can be customized using comparison Options.
Package http://pkg.go.dev/gotest.tools/v3/assert/opt provides some additional
commonly used Options.
Equal succeeds if x == y. See assert.Equal for full documentation.
Error succeeds if err is a non-nil error, and the error message equals the
expected message.
ErrorContains succeeds if err is a non-nil error, and the error message contains
the expected substring.
ErrorIs succeeds if errors.Is(actual, expected) returns true. See
https://golang.org/pkg/errors/#Is for accepted argument values.
ErrorType succeeds if err is not nil and is of the expected type.
Expected can be one of:
func(error) bool
Function should return true if the error is the expected type.
type struct{}, type &struct{}
A struct or a pointer to a struct.
Fails if the error is not of the same type as expected.
type &interface{}
A pointer to an interface type.
Fails if err does not implement the interface.
reflect.Type
Fails if err does not implement the reflect.Type
Len succeeds if the sequence has the expected length.
Nil succeeds if obj is a nil interface, pointer, or function.
Use NilError() for comparing errors. Use Len(obj, 0) for comparing slices,
maps, and channels.
Panics succeeds if f() panics.
Regexp succeeds if value v matches regular expression re.
Example:
assert.Assert(t, cmp.Regexp("^[0-9a-f]{32}$", str))
r := regexp.MustCompile("^[0-9a-f]{32}$")
assert.Assert(t, cmp.Regexp(r, str))
ResultFailure returns a failed Result with a failure message.
ResultFailureTemplate returns a Result with a template string and data which
can be used to format a failure message. The template may access data from .Data,
the comparison args with the callArg function, and the formatNode function may
be used to format the call args.
ResultFromError returns ResultSuccess if err is nil. Otherwise ResultFailure
is returned with the error message as the failure message.
Package-Level Variables (total 3, in which 1 are exported)
ResultSuccess is a constant which is returned by a ComparisonWithResult to
indicate success.
The pages are generated with Golds v0.4.9. (GOOS=linux GOARCH=amd64)