Documentation ¶
Overview ¶
Package testerr provides some helpers to check errors from calls in unit tests.
Especially if the errors are not the focus of the test, it is useful to also check these errors - especially those accompanying other return values - without distracting too much from the actual test.
Test functions in testerr that begin with "Should" call the error function of a test if the test fails. Test functions that begin with "Shall" call the fatal function of the test if the test fails.
Example ¶
var t *testing.T testedFunc := func() (int, error) { return 4711, nil } // In plain Go: n, err := testedFunc() if err != nil { t.Fatalf("illegal error: %s", err) } if n < 0 || n > 10000 { t.Errorf("%d out of range", n) } // Short, but possibly misleading results: n, _ = testedFunc() if n < 0 || n > 10000 { t.Errorf("%d out of range", n) } // Using testerr: n = F1(testedFunc()).ShallBeNil(t) if n < 0 || n > 10000 { t.Errorf("%d out of range", n) }
Output:
Index ¶
- func Is(target error) func(error) error
- func IsNull(err error) error
- func Msg(format string, args ...any) func(error) error
- func MsgContains(format string, args ...any) func(error) error
- func MsgMatch(expr string) func(error) error
- func MsgPrefix(format string, args ...any) func(error) error
- func MsgSuffix(format string, args ...any) func(error) error
- func NotNull(err error) error
- type F0Error
- func (pe F0Error) ShallAll(t testing.TB, checks ...func(error) error) error
- func (pe F0Error) ShallAny(t testing.TB, checks ...func(error) error) error
- func (pe F0Error) ShallBe(t testing.TB, target error) error
- func (pe F0Error) ShallBeNil(t testing.TB)
- func (pe F0Error) ShallMsg(t testing.TB, format string, args ...any) error
- func (pe F0Error) ShallNotNil(t testing.TB) error
- func (pe F0Error) ShouldAll(t testing.TB, checks ...func(error) error) error
- func (pe F0Error) ShouldAny(t testing.TB, checks ...func(error) error) error
- func (pe F0Error) ShouldBe(t testing.TB, target error) error
- func (pe F0Error) ShouldBeNil(t testing.TB) error
- func (pe F0Error) ShouldMsg(t testing.TB, format string, args ...any) error
- func (pe F0Error) ShouldNotNil(t testing.TB) error
- type F1Error
- func (fe F1Error[R]) ShallAll(t testing.TB, checks ...func(error) error) R
- func (fe F1Error[R]) ShallAny(t testing.TB, checks ...func(error) error) R
- func (fe F1Error[R]) ShallBe(t testing.TB, target error) R
- func (fe F1Error[R]) ShallBeNil(t testing.TB) R
- func (fe F1Error[R]) ShallMsg(t testing.TB, format string, args ...any) R
- func (fe F1Error[R]) ShallNotNil(t testing.TB) R
- func (fe F1Error[R]) ShouldAll(t testing.TB, checks ...func(error) error) R
- func (fe F1Error[R]) ShouldAny(t testing.TB, checks ...func(error) error) R
- func (fe F1Error[R]) ShouldBe(t testing.TB, target error) R
- func (fe F1Error[R]) ShouldBeNil(t testing.TB) R
- func (fe F1Error[R]) ShouldMsg(t testing.TB, format string, args ...any) R
- func (fe F1Error[R]) ShouldNotNil(t testing.TB) R
- type F2Error
- func (fe F2Error[R, T]) ShallAll(t testing.TB, checks ...func(error) error) (R, T)
- func (fe F2Error[R, T]) ShallAny(t testing.TB, checks ...func(error) error) (R, T)
- func (fe F2Error[R, T]) ShallBe(t testing.TB, target error) (R, T)
- func (fe F2Error[R, T]) ShallBeNil(t testing.TB) (R, T)
- func (fe F2Error[R, T]) ShallMsg(t testing.TB, format string, args ...any) (R, T)
- func (fe F2Error[R, T]) ShallNotNil(t testing.TB) (R, T)
- func (fe F2Error[R, T]) ShouldAll(t testing.TB, checks ...func(error) error) (R, T)
- func (fe F2Error[R, T]) ShouldAny(t testing.TB, checks ...func(error) error) (R, T)
- func (fe F2Error[R, T]) ShouldBe(t testing.TB, target error) (R, T)
- func (fe F2Error[R, T]) ShouldBeNil(t testing.TB) (R, T)
- func (fe F2Error[R, T]) ShouldMsg(t testing.TB, format string, args ...any) (R, T)
- func (fe F2Error[R, T]) ShouldNotNil(t testing.TB) (R, T)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type F0Error ¶
type F0Error struct {
// contains filtered or unexported fields
}
func (F0Error) ShallBeNil ¶
type F1Error ¶
type F1Error[R any] struct { // contains filtered or unexported fields }
func (F1Error[R]) ShallBeNil ¶
func (F1Error[R]) ShallNotNil ¶
func (F1Error[R]) ShouldBeNil ¶
func (F1Error[R]) ShouldNotNil ¶
type F2Error ¶
type F2Error[R, T any] struct { // contains filtered or unexported fields }
func (F2Error[R, T]) ShallBeNil ¶
func (F2Error[R, T]) ShallNotNil ¶
func (F2Error[R, T]) ShouldBeNil ¶
func (F2Error[R, T]) ShouldNotNil ¶
Click to show internal directories.
Click to hide internal directories.