Documentation ¶
Index ¶
- Variables
- type Context
- func (c Context) AddArrayIndex(index int) (new Context)
- func (c Context) AddCustomLevel(pathAdd string) (new Context)
- func (c Context) AddField(field string) (new Context)
- func (c Context) AddFunctionCall(fn string) (new Context)
- func (c Context) AddMapKey(key interface{}) (new Context)
- func (c Context) AddPtr(num int) (new Context)
- func (c Context) CannotCompareError() *Error
- func (c Context) CollectError(err *Error) *Error
- func (c *Context) InitErrors()
- func (c Context) MergeErrors() *Error
- func (c Context) ResetErrors() (new Context)
- func (c Context) ResetPath(newRoot string) (new Context)
- type Error
- type ErrorSummary
- type ErrorSummaryItem
- type ErrorSummaryItems
- type Path
- func (p Path) AddArrayIndex(index int) Path
- func (p Path) AddCustomLevel(custom string) Path
- func (p Path) AddField(field string) Path
- func (p Path) AddFunctionCall(fn string) Path
- func (p Path) AddMapKey(key interface{}) Path
- func (p Path) AddPtr(num int) Path
- func (p Path) Copy() Path
- func (p Path) Equal(o Path) bool
- func (p Path) Len() int
- func (p Path) String() string
Constants ¶
This section is empty.
Variables ¶
var ( // BooleanError is the *Error returned when an error occurs in a // boolean context. BooleanError = &Error{} // ErrTooManyErrors is chained to the last error encountered when // the maximum number of errors has been reached. ErrTooManyErrors = &Error{ Message: "Too many errors (use TESTDEEP_MAX_ERRORS=-1 to see all)", } )
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct { Path Path Visited visited.Visited CurOperator location.GetLocationer Depth int // 0 ≤ MaxErrors ≤ 1 stops when first error encoutered (without the // "Too many errors" error); // MaxErrors > 1 stops when MaxErrors'th error encoutered (with a // last "Too many errors" error); // < 0 do not stop until comparison ends. MaxErrors int Errors *[]*Error Anchors *anchors.Info Hooks *hooks.Info // If true, the contents of the returned *Error will not be // checked. Can be used to avoid filling Error{} with expensive // computations. BooleanError bool // See ContextConfig.FailureIsFatal for details. FailureIsFatal bool // See ContextConfig.UseEqual for details. UseEqual bool // See ContextConfig.BeLax for details. BeLax bool }
Context is used internally to keep track of the CmpDeeply in-Depth traversal.
func (Context) AddArrayIndex ¶
AddArrayIndex creates a new Context from current one plus an array dereference for index-th item.
func (Context) AddCustomLevel ¶ added in v1.1.0
AddCustomLevel creates a new Context from current one plus pathAdd.
func (Context) AddField ¶ added in v1.1.0
AddField creates a new Context from current one plus "." + field.
func (Context) AddFunctionCall ¶
AddFunctionCall creates a new Context from current one inside a function call.
func (Context) AddMapKey ¶
AddMapKey creates a new Context from current one plus a map dereference for key key.
func (Context) CannotCompareError ¶ added in v1.1.1
CannotCompareError returns a generic error used when the access of unexported fields cannot be overridden.
func (Context) CollectError ¶
CollectError collects an error in the context. It returns an error if the collector is full, nil otherwise.
In boolean context, ignore the passed error and return the BooleanError.
func (*Context) InitErrors ¶
func (c *Context) InitErrors()
InitErrors initializes Context *Errors slice, if MaxErrors < 0 or MaxErrors > 1.
func (Context) MergeErrors ¶
MergeErrors merges all collected errors in the first one and returns it. It returns nil if no errors have been collected.
func (Context) ResetErrors ¶
ResetErrors returns a new Context without any Error set.
type Error ¶
type Error struct { // Context when the error occurred Context Context // Message describes the error Message string // Got value Got interface{} // Expected value Expected interface{} // If not nil, Summary is used to display summary instead of using // Got + Expected fields Summary ErrorSummary // If initialized, location of TestDeep operator originator of the error Location location.Location // If defined, the current Error comes from this Error Origin *Error // If defined, points to the next Error Next *Error }
Error represents errors generated by td (go-testdeep) functions.
func TypeMismatch ¶ added in v1.8.0
TypeMismatch returns a "type mismatch" error. It is the caller responsibility to check that both types differ.
If they resolve to the same name (via their String method), it tries to deeply dump the full package name of each type.
It works pretty well with the exception of identical anomymous structs in 2 different packages with the same last name: in this case reflect does not allow us to retrieve the package from which each type comes.
package foo // in a/ var Foo struct { a int } package foo // in b/ var Foo struct { a int } package ctxerr import( a_foo "a/foo" b_foo "b/foo" ) … TypeMismatch(reflect.TypeOf(a_foo.Foo), reflect.TypeOf(b_foo.Foo))
returns an error producing:
type mismatch got: struct { a int } expected: struct { a int }
func (*Error) Append ¶
Append appends the Error contents to "buf" using prefix "prefix" for each line.
func (*Error) ExpectedString ¶
ExpectedString returns the string corresponding to the Expected field. Returns the empty string if the Error Summary field is not nil.
func (*Error) GotString ¶
GotString returns the string corresponding to the Got field. Returns the empty string if the Error Summary field is not nil.
func (*Error) SummaryString ¶
SummaryString returns the string corresponding to the Summary field. Returns the empty string if the Error Summary field is nil.
type ErrorSummary ¶ added in v1.1.0
ErrorSummary is the interface used to render error summaries. See Error.Summary.
func NewSummary ¶ added in v1.1.0
func NewSummary(s string) ErrorSummary
NewSummary returns an ErrorSummary composed by the simple string s.
func NewSummaryReason ¶ added in v1.1.0
func NewSummaryReason(got interface{}, reason string) ErrorSummary
NewSummaryReason returns an ErrorSummary meaning that the value got failed for an (optional) reason.
With a given reason "it is not nil", the generated summary will be:
value: the_got_value it failed coz: it is not nil
If reason is empty, the generated summary will be:
value: the_got_value it failed but didn't say why
type ErrorSummaryItem ¶ added in v1.1.0
ErrorSummaryItem implements the ErrorSummary interface and allows to render a labeled value.
With explanation set:
Label: value Explanation
With an empty explantion:
Label: value
func (ErrorSummaryItem) AppendSummary ¶ added in v1.1.0
func (s ErrorSummaryItem) AppendSummary(buf *bytes.Buffer, prefix string)
AppendSummary implements the ErrorSummary interface.
type ErrorSummaryItems ¶ added in v1.1.0
type ErrorSummaryItems []ErrorSummaryItem
ErrorSummaryItems implements the ErrorSummary interface and allows to render summaries with several labeled values. For example:
Missing 6 items: the 6 items... Extra 2 items: the 2 items...
func (ErrorSummaryItems) AppendSummary ¶ added in v1.1.0
func (s ErrorSummaryItems) AppendSummary(buf *bytes.Buffer, prefix string)
AppendSummary implements ErrorSummary interface.
type Path ¶ added in v1.1.0
type Path []pathLevel
Path defines a structure depth path, typically used to mark a position during a deep traversal in case of error.
func (Path) AddArrayIndex ¶ added in v1.1.0
AddArrayIndex adds a level corresponding to an array index.
func (Path) AddCustomLevel ¶ added in v1.1.0
AddCustomLevel adds a custom level.
func (Path) AddFunctionCall ¶ added in v1.1.0
AddFunctionCall adds a level corresponding to a function call.