Documentation
¶
Overview ¶
Package assert provides some tool functions for use with the Go testing.
inspired the package: github.com/stretchr/testify/assert
Index ¶
- Variables
- func Contains(t TestingT, src, elem any, fmtAndArgs ...any) bool
- func ContainsKey(t TestingT, mp, key any, fmtAndArgs ...any) bool
- func DisableColor()
- func Empty(t TestingT, give any, fmtAndArgs ...any) bool
- func Eq(t TestingT, want, give any, fmtAndArgs ...any) bool
- func Err(t TestingT, err error, fmtAndArgs ...any) bool
- func ErrMsg(t TestingT, err error, wantMsg string, fmtAndArgs ...any) bool
- func ErrSubMsg(t TestingT, err error, subMsg string, fmtAndArgs ...any) bool
- func Fail(t TestingT, failMsg string, fmtAndArgs ...any) bool
- func FailNow(t TestingT, failMsg string, fmtAndArgs ...any) bool
- func False(t TestingT, give bool, fmtAndArgs ...any) bool
- func Gt(t TestingT, give, min int, fmtAndArgs ...any) bool
- func HideFullPath()
- func Len(t TestingT, give any, wantLn int, fmtAndArgs ...any) bool
- func LenGt(t TestingT, give any, minLn int, fmtAndArgs ...any) bool
- func Lt(t TestingT, give, max int, fmtAndArgs ...any) bool
- func Neq(t TestingT, want, give any, fmtAndArgs ...any) bool
- func Nil(t TestingT, give any, fmtAndArgs ...any) bool
- func NoErr(t TestingT, err error, fmtAndArgs ...any) bool
- func NotContains(t TestingT, src, elem any, fmtAndArgs ...any) bool
- func NotEmpty(t TestingT, give any, fmtAndArgs ...any) bool
- func NotEq(t TestingT, want, give any, fmtAndArgs ...any) bool
- func NotNil(t TestingT, give any, fmtAndArgs ...any) bool
- func NotPanics(t TestingT, fn PanicRunFunc, fmtAndArgs ...any) bool
- func Panics(t TestingT, fn PanicRunFunc, fmtAndArgs ...any) bool
- func PanicsErrMsg(t TestingT, fn PanicRunFunc, errMsg string, fmtAndArgs ...any) bool
- func PanicsMsg(t TestingT, fn PanicRunFunc, wantVal interface{}, fmtAndArgs ...any) bool
- func StrContains(t TestingT, s, sub string, fmtAndArgs ...any) bool
- func True(t TestingT, give bool, fmtAndArgs ...any) bool
- type Assertions
- func (as *Assertions) Contains(src, elem any, fmtAndArgs ...any) *Assertions
- func (as *Assertions) ContainsKey(mp, key any, fmtAndArgs ...any) *Assertions
- func (as *Assertions) Empty(give any, fmtAndArgs ...any) *Assertions
- func (as *Assertions) Eq(want, give any, fmtAndArgs ...any) *Assertions
- func (as *Assertions) Err(err error, fmtAndArgs ...any) *Assertions
- func (as *Assertions) ErrMsg(err error, errMsg string, fmtAndArgs ...any) *Assertions
- func (as *Assertions) ErrSubMsg(err error, subMsg string, fmtAndArgs ...any) *Assertions
- func (as *Assertions) Fail(failMsg string, fmtAndArgs ...any) *Assertions
- func (as *Assertions) FailNow(failMsg string, fmtAndArgs ...any) *Assertions
- func (as *Assertions) False(give bool, fmtAndArgs ...any) *Assertions
- func (as *Assertions) Gt(give, min int, fmtAndArgs ...any) *Assertions
- func (as Assertions) IsFail() bool
- func (as Assertions) IsOk() bool
- func (as *Assertions) Len(give any, wantLn int, fmtAndArgs ...any) *Assertions
- func (as *Assertions) LenGt(give any, minLn int, fmtAndArgs ...any) *Assertions
- func (as *Assertions) Lt(give, max int, fmtAndArgs ...any) *Assertions
- func (as *Assertions) Neq(want, give any, fmtAndArgs ...any) *Assertions
- func (as *Assertions) Nil(give any, fmtAndArgs ...any) *Assertions
- func (as *Assertions) NoErr(err error, fmtAndArgs ...any) *Assertions
- func (as *Assertions) NotContains(src, elem any, fmtAndArgs ...any) *Assertions
- func (as *Assertions) NotEmpty(give any, fmtAndArgs ...any) *Assertions
- func (as *Assertions) NotEq(want, give any, fmtAndArgs ...any) *Assertions
- func (as *Assertions) NotNil(val any, fmtAndArgs ...any) *Assertions
- func (as *Assertions) NotPanics(fn PanicRunFunc, fmtAndArgs ...any) *Assertions
- func (as *Assertions) Panics(fn PanicRunFunc, fmtAndArgs ...any) *Assertions
- func (as *Assertions) PanicsErrMsg(fn PanicRunFunc, errMsg string, fmtAndArgs ...any) *Assertions
- func (as *Assertions) PanicsMsg(fn PanicRunFunc, wantVal interface{}, fmtAndArgs ...any) *Assertions
- func (as *Assertions) StrContains(s, sub string, fmtAndArgs ...any) *Assertions
- func (as *Assertions) True(give bool, fmtAndArgs ...any) *Assertions
- type PanicRunFunc
- type TestingT
Constants ¶
This section is empty.
Variables ¶
var ( // ShowFullPath on show error trace ShowFullPath = true // EnableColor on show error trace EnableColor = true )
Functions ¶
func Contains ¶
Contains asserts that the given data(string,slice,map) should contain element
TIP: only support types: string, map, array, slice
map - check key exists string - check sub-string exists array,slice - check sub-element exists
func ContainsKey ¶
ContainsKey asserts that the given map is contains key
func ErrSubMsg ¶
ErrSubMsg asserts that the given is a not nil error and the error message contains subMsg
func NotContains ¶ added in v0.5.7
NotContains asserts that the given data(string,slice,map) should not contain element
TIP: only support types: string, map, array, slice
map - check key exists string - check sub-string exists array,slice - check sub-element exists
func NotPanics ¶
func NotPanics(t TestingT, fn PanicRunFunc, fmtAndArgs ...any) bool
NotPanics asserts that the code inside the specified func NOT panics.
func Panics ¶
func Panics(t TestingT, fn PanicRunFunc, fmtAndArgs ...any) bool
Panics asserts that the code inside the specified func panics.
func PanicsErrMsg ¶
func PanicsErrMsg(t TestingT, fn PanicRunFunc, errMsg string, fmtAndArgs ...any) bool
PanicsErrMsg should panic and with error message
func PanicsMsg ¶
func PanicsMsg(t TestingT, fn PanicRunFunc, wantVal interface{}, fmtAndArgs ...any) bool
PanicsMsg should panic and with a value
func StrContains ¶
StrContains asserts that the given strings is contains sub-string
Types ¶
type Assertions ¶
type Assertions struct {
// contains filtered or unexported fields
}
Assertions provides assertion methods around the TestingT interface.
func New ¶
func New(t TestingT) *Assertions
New makes a new Assertions object for the specified TestingT.
func (*Assertions) Contains ¶
func (as *Assertions) Contains(src, elem any, fmtAndArgs ...any) *Assertions
func (*Assertions) ContainsKey ¶
func (as *Assertions) ContainsKey(mp, key any, fmtAndArgs ...any) *Assertions
func (*Assertions) Empty ¶
func (as *Assertions) Empty(give any, fmtAndArgs ...any) *Assertions
func (*Assertions) Eq ¶
func (as *Assertions) Eq(want, give any, fmtAndArgs ...any) *Assertions
func (*Assertions) Err ¶
func (as *Assertions) Err(err error, fmtAndArgs ...any) *Assertions
Err asserts that the given is a not nil error
func (*Assertions) ErrMsg ¶
func (as *Assertions) ErrMsg(err error, errMsg string, fmtAndArgs ...any) *Assertions
func (*Assertions) ErrSubMsg ¶
func (as *Assertions) ErrSubMsg(err error, subMsg string, fmtAndArgs ...any) *Assertions
func (*Assertions) Fail ¶
func (as *Assertions) Fail(failMsg string, fmtAndArgs ...any) *Assertions
func (*Assertions) FailNow ¶
func (as *Assertions) FailNow(failMsg string, fmtAndArgs ...any) *Assertions
func (*Assertions) False ¶
func (as *Assertions) False(give bool, fmtAndArgs ...any) *Assertions
func (*Assertions) Gt ¶
func (as *Assertions) Gt(give, min int, fmtAndArgs ...any) *Assertions
func (*Assertions) Len ¶
func (as *Assertions) Len(give any, wantLn int, fmtAndArgs ...any) *Assertions
func (*Assertions) LenGt ¶
func (as *Assertions) LenGt(give any, minLn int, fmtAndArgs ...any) *Assertions
func (*Assertions) Lt ¶
func (as *Assertions) Lt(give, max int, fmtAndArgs ...any) *Assertions
func (*Assertions) Neq ¶
func (as *Assertions) Neq(want, give any, fmtAndArgs ...any) *Assertions
func (*Assertions) Nil ¶
func (as *Assertions) Nil(give any, fmtAndArgs ...any) *Assertions
func (*Assertions) NoErr ¶
func (as *Assertions) NoErr(err error, fmtAndArgs ...any) *Assertions
NoErr asserts that the given is a nil error
func (*Assertions) NotContains ¶ added in v0.5.7
func (as *Assertions) NotContains(src, elem any, fmtAndArgs ...any) *Assertions
func (*Assertions) NotEmpty ¶
func (as *Assertions) NotEmpty(give any, fmtAndArgs ...any) *Assertions
func (*Assertions) NotEq ¶
func (as *Assertions) NotEq(want, give any, fmtAndArgs ...any) *Assertions
func (*Assertions) NotNil ¶
func (as *Assertions) NotNil(val any, fmtAndArgs ...any) *Assertions
NotNil asserts that the given is a not nil value
func (*Assertions) NotPanics ¶
func (as *Assertions) NotPanics(fn PanicRunFunc, fmtAndArgs ...any) *Assertions
func (*Assertions) Panics ¶
func (as *Assertions) Panics(fn PanicRunFunc, fmtAndArgs ...any) *Assertions
func (*Assertions) PanicsErrMsg ¶
func (as *Assertions) PanicsErrMsg(fn PanicRunFunc, errMsg string, fmtAndArgs ...any) *Assertions
func (*Assertions) PanicsMsg ¶
func (as *Assertions) PanicsMsg(fn PanicRunFunc, wantVal interface{}, fmtAndArgs ...any) *Assertions
func (*Assertions) StrContains ¶
func (as *Assertions) StrContains(s, sub string, fmtAndArgs ...any) *Assertions
func (*Assertions) True ¶
func (as *Assertions) True(give bool, fmtAndArgs ...any) *Assertions