Documentation ¶
Overview ¶
Package assert implements assertions for the standard testing package.
Index ¶
- func AsErr[T Param](t TB, err error, target any, formatAndArgs ...any)
- func Equal[T Param, V any](t TB, got, want V, formatAndArgs ...any)
- func IsErr[T Param](t TB, err, target error, formatAndArgs ...any)
- func NoErr[T Param](t TB, err error, formatAndArgs ...any)
- func Panics[T Param](t TB, fn func(), v any, formatAndArgs ...any)
- type E
- type F
- type Param
- type TB
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsErr ¶
AsErr asserts that errors.As(err, target) is true.
Example ¶
assert.AsErr[E](t, err, new(*os.PathError))
Output: errors.As() mismatch got: *errors.errorString want: *fs.PathError
func Equal ¶
Equal asserts that two values are equal.
Example ¶
assert.Equal[E](t, 1, 2)
Output: values are not equal got: 1 want: 2
func IsErr ¶
IsErr asserts that errors.Is(err, target) is true.
Example ¶
assert.IsErr[E](t, err, os.ErrNotExist)
Output: errors.Is() mismatch got: file already exists want: file does not exist
func NoErr ¶
NoErr asserts that the error is nil.
Example ¶
assert.NoErr[E](t, err)
Output: unexpected error: file already exists
Types ¶
type E ¶
type E struct{}
E is a Param that marks the test as failed but continues execution (similar to testing.T.Errorf).
type F ¶
type F struct{}
F is a Param that marks the test as failed and stops execution (similar to testing.T.Fatalf).
Click to show internal directories.
Click to hide internal directories.