testerr

package module
v0.0.0-...-b4fc611 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 5 Imported by: 0

README

testerr

Go Reference

Testing helpers for Go to check errors from function calls.

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Is

func Is(target error) func(error) error

func IsNull

func IsNull(err error) error

func Msg

func Msg(format string, args ...any) func(error) error

func MsgContains

func MsgContains(format string, args ...any) func(error) error

func MsgMatch

func MsgMatch(expr string) func(error) error

func MsgPrefix

func MsgPrefix(format string, args ...any) func(error) error

func MsgSuffix

func MsgSuffix(format string, args ...any) func(error) error

func NotNull

func NotNull(err error) error

Types

type F0Error

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

func F0

func F0(err error) F0Error

F0 captures the error from a call to then apply further checks to the error.

func (F0Error) ShallAll

func (pe F0Error) ShallAll(t testing.TB, checks ...func(error) error) error

func (F0Error) ShallAny

func (pe F0Error) ShallAny(t testing.TB, checks ...func(error) error) error

func (F0Error) ShallBe

func (pe F0Error) ShallBe(t testing.TB, target error) error

func (F0Error) ShallBeNil

func (pe F0Error) ShallBeNil(t testing.TB)

func (F0Error) ShallMsg

func (pe F0Error) ShallMsg(t testing.TB, format string, args ...any) error

func (F0Error) ShallNotNil

func (pe F0Error) ShallNotNil(t testing.TB) error

func (F0Error) ShouldAll

func (pe F0Error) ShouldAll(t testing.TB, checks ...func(error) error) error

func (F0Error) ShouldAny

func (pe F0Error) ShouldAny(t testing.TB, checks ...func(error) error) error

func (F0Error) ShouldBe

func (pe F0Error) ShouldBe(t testing.TB, target error) error

func (F0Error) ShouldBeNil

func (pe F0Error) ShouldBeNil(t testing.TB) error

func (F0Error) ShouldMsg

func (pe F0Error) ShouldMsg(t testing.TB, format string, args ...any) error

func (F0Error) ShouldNotNil

func (pe F0Error) ShouldNotNil(t testing.TB) error

type F1Error

type F1Error[R any] struct {
	// contains filtered or unexported fields
}

func F1

func F1[R any](v R, err error) F1Error[R]

F1 captures the result and error from a call to then apply further checks to the error.

func (F1Error[R]) ShallAll

func (fe F1Error[R]) ShallAll(t testing.TB, checks ...func(error) error) R

func (F1Error[R]) ShallAny

func (fe F1Error[R]) ShallAny(t testing.TB, checks ...func(error) error) R

func (F1Error[R]) ShallBe

func (fe F1Error[R]) ShallBe(t testing.TB, target error) R

func (F1Error[R]) ShallBeNil

func (fe F1Error[R]) ShallBeNil(t testing.TB) R

func (F1Error[R]) ShallMsg

func (fe F1Error[R]) ShallMsg(t testing.TB, format string, args ...any) R

func (F1Error[R]) ShallNotNil

func (fe F1Error[R]) ShallNotNil(t testing.TB) R

func (F1Error[R]) ShouldAll

func (fe F1Error[R]) ShouldAll(t testing.TB, checks ...func(error) error) R

func (F1Error[R]) ShouldAny

func (fe F1Error[R]) ShouldAny(t testing.TB, checks ...func(error) error) R

func (F1Error[R]) ShouldBe

func (fe F1Error[R]) ShouldBe(t testing.TB, target error) R

func (F1Error[R]) ShouldBeNil

func (fe F1Error[R]) ShouldBeNil(t testing.TB) R

func (F1Error[R]) ShouldMsg

func (fe F1Error[R]) ShouldMsg(t testing.TB, format string, args ...any) R

func (F1Error[R]) ShouldNotNil

func (fe F1Error[R]) ShouldNotNil(t testing.TB) R

type F2Error

type F2Error[R, T any] struct {
	// contains filtered or unexported fields
}

func F2

func F2[R, T any](u R, v T, err error) F2Error[R, T]

F2 captures the results and error from a call to then apply further checks to the error.

func (F2Error[R, T]) ShallAll

func (fe F2Error[R, T]) ShallAll(t testing.TB, checks ...func(error) error) (R, T)

func (F2Error[R, T]) ShallAny

func (fe F2Error[R, T]) ShallAny(t testing.TB, checks ...func(error) error) (R, T)

func (F2Error[R, T]) ShallBe

func (fe F2Error[R, T]) ShallBe(t testing.TB, target error) (R, T)

func (F2Error[R, T]) ShallBeNil

func (fe F2Error[R, T]) ShallBeNil(t testing.TB) (R, T)

func (F2Error[R, T]) ShallMsg

func (fe F2Error[R, T]) ShallMsg(t testing.TB, format string, args ...any) (R, T)

func (F2Error[R, T]) ShallNotNil

func (fe F2Error[R, T]) ShallNotNil(t testing.TB) (R, T)

func (F2Error[R, T]) ShouldAll

func (fe F2Error[R, T]) ShouldAll(t testing.TB, checks ...func(error) error) (R, T)

func (F2Error[R, T]) ShouldAny

func (fe F2Error[R, T]) ShouldAny(t testing.TB, checks ...func(error) error) (R, T)

func (F2Error[R, T]) ShouldBe

func (fe F2Error[R, T]) ShouldBe(t testing.TB, target error) (R, T)

func (F2Error[R, T]) ShouldBeNil

func (fe F2Error[R, T]) ShouldBeNil(t testing.TB) (R, T)

func (F2Error[R, T]) ShouldMsg

func (fe F2Error[R, T]) ShouldMsg(t testing.TB, format string, args ...any) (R, T)

func (F2Error[R, T]) ShouldNotNil

func (fe F2Error[R, T]) ShouldNotNil(t testing.TB) (R, T)

Jump to

Keyboard shortcuts

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