Documentation ¶
Overview ¶
Package assert helps writing assertions for tests. Benefits include brevity, clarity, and helpful error messages.
If .T(t) is specified, failures are reported with t.Error which means multiple errors may be reported. If .T(t) is not specified, panic is called with the error string.
For example:
assert.That(a || b) assert.This(x).Is(y) assert.T(t).This(x).Like(y) assert.Msg("first time").That(a || b) assert.T(t).Msg("second").This(fn).Panics("illegal")
Use a variable to avoid specifying .T(t) repeatedly:
assert := assert.T(t) assert.This(x).Is(y)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Catch ¶
func Catch(f func()) (result any)
Catch calls the given function, catching and returning panics
func False ¶
func False(b bool)
False gives an error if the value is not true. False(x) is the same as That(!x)
func Msg ¶
func Msg(args ...any) assert
Msg adds additional information to print with the error. It can be useful with That/True/False where the error is not very helpful.
func Nil ¶
func Nil(v any)
Nil gives an error if the value is not nil. It handles nil func/pointer/slice/map/channel using reflect.IsNil For performance critical code, consider using That(value == nil)
func ShouldNotReachHere ¶
func ShouldNotReachHere() int
Types ¶
This section is empty.