format - ActiveState ActiveGo 1.8

Package format

import ""

Overview ▾

Gomega's format package pretty-prints objects. It explores input objects recursively and generates formatted, indented output with type information.


The default indentation string emitted by the format package

var Indent = "    "

Use MaxDepth to set the maximum recursion depth when printing deeply nested objects

var MaxDepth = uint(10)

Print the content of context objects. By default it will be suppressed.

Set PrintContextObjects = true to enable printing of the context internals.

var PrintContextObjects = false

By default, all objects (even those that implement fmt.Stringer and fmt.GoStringer) are recursively inspected to generate output.

Set UseStringerRepresentation = true to use GoString (for fmt.GoStringers) or String (for fmt.Stringer) instead.

Note that GoString and String don't always have all the information you need to understand why a test failed!

var UseStringerRepresentation = false

func IndentString

func IndentString(s string, indentation uint) string

IndentString takes a string and indents each line by the specified amount.

func Message

func Message(actual interface{}, message string, expected ...interface{}) string

Generates a formatted matcher success/failure message of the form:

	<pretty printed actual>
	<pretty printed expected>

If expected is omited, then the message looks like:

	<pretty printed actual>

func MessageWithDiff

func MessageWithDiff(actual, message, expected string) string

func Object

func Object(object interface{}, indentation uint) string

Pretty prints the passed in object at the passed in indentation level.

Object recurses into deeply nested objects emitting pretty-printed representations of their components.

Modify format.MaxDepth to control how deep the recursion is allowed to go Set format.UseStringerRepresentation to true to return object.GoString() or object.String() when available instead of recursing into the object.

Set PrintContextObjects to true to print the content of objects implementing context.Context

type Ctx

Ctx interface defined here to keep backwards compatability with go < 1.7 It matches the context.Context interface

type Ctx interface {
    Deadline() (deadline time.Time, ok bool)
    Done() <-chan struct{}
    Err() error
    Value(key interface{}) interface{}