assert

package
v1.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

type Result struct {
	// contains filtered or unexported fields
}

Result contains a single assertion failure as an error. You should not create a Result directly, use So instead. Once created, a Result is read-only and only allows queries using the provided methods.

func So

func So(actual interface{}, assert assertion, expected ...interface{}) *Result

So is a convenience function (as opposed to an inconvenience function?) for running assertions on arbitrary arguments in any context. It allows you to perform assertion-like behavior and decide what happens in the event of a failure. It is a variant of assertions.So in every respect except its return value. In this case, the return value is a *Result which possesses several of its own convenience methods:

fmt.Println(assert.So(1, should.Equal, 1)) // Calls String() and prints the representation of the assertion.
assert.So(1, should.Equal, 1).Println()    // Calls fmt.Print with the failure message and file:line header.
assert.So(1, should.Equal, 1).Log()        // Calls log.Print with the failure message and file:line header.
assert.So(1, should.Equal, 1).Panic()      // Calls log.Panic with the failure message and file:line header.
assert.So(1, should.Equal, 1).Fatal()      // Calls log.Fatal with the failure message and file:line header.
if err := assert.So(1, should.Equal, 1).Error(); err != nil {
    // Allows custom handling of the error, which will include the failure message and file:line header.
}

func (*Result) Error

func (this *Result) Error() error

Error returns the error representing an assertion failure, which is nil in the case of a passed assertion.

func (*Result) Failed

func (this *Result) Failed() bool

Failed returns true if the assertion failed, false if it passed.

func (*Result) Fatal

func (this *Result) Fatal() *Result

Fatal calls log.Fatal in the case of an assertion failure.

func (*Result) Log

func (this *Result) Log() *Result

Log calls log.Print in the case of an assertion failure.

func (*Result) Panic

func (this *Result) Panic() *Result

Panic calls log.Panic in the case of an assertion failure.

func (*Result) Passed

func (this *Result) Passed() bool

Passed returns true if the assertion passed, false if it failed.

func (*Result) Println

func (this *Result) Println() *Result

Println calls fmt.Println in the case of an assertion failure.

func (*Result) String

func (this *Result) String() string

String implements fmt.Stringer. It returns the error as a string in the case of an assertion failure. Unlike other methods defined herein, if returns a non-empty representation of the assertion as confirmation of success.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL