Documentation
¶
Overview ¶
Package assert provides an incredibly simple assertion framework, that relies on generics and simplicity. All assertions are "fatal" and cause the test to abort at the failure line (rather than continue on error).
Index ¶
- func Contains[T comparable](t testing.TB, slice []T, item T)
- func Equal[T comparable](t testing.TB, valOne, valTwo T)
- func EqualItems[T comparable](t testing.TB, one, two []T)
- func Error(t testing.TB, err error)
- func ErrorIs(t testing.TB, err, target error)
- func Failing[T testing.TB](t T, test func(T))
- func MaxRuntime(t testing.TB, dur time.Duration, op func())
- func MinRuntime(t testing.TB, dur time.Duration, op func())
- func NotContains[T comparable](t testing.TB, slice []T, item T)
- func NotEqual[T comparable](t testing.TB, valOne, valTwo T)
- func NotEqualItems[T comparable](t testing.TB, one, two []T)
- func NotError(t testing.TB, err error)
- func NotErrorIs(t testing.TB, err, target error)
- func NotPanic(t testing.TB, fn func())
- func NotSubstring(t testing.TB, str, substr string)
- func NotType[T any](t testing.TB, obj any)
- func NotZero[T comparable](t testing.TB, val T)
- func Panic(t testing.TB, fn func())
- func PanicValue[T comparable](t testing.TB, fn func(), value T)
- func Substring(t testing.TB, str, substr string)
- func True(t testing.TB, cond bool)
- func Type[T any](t testing.TB, obj any)
- func Zero[T comparable](t testing.TB, val T)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
func Contains[T comparable](t testing.TB, slice []T, item T)
Contains asserts that the item is in the slice provided. Empty or nil slices always cause failure.
func Equal ¶
func Equal[T comparable](t testing.TB, valOne, valTwo T)
Equal causes a test to fail if the two (comparable) values are not equal. Be aware that two different pointers and objects passed as interfaces that are implemented by pointer receivers are comparable as equal and will fail this assertion even if their *values* are equal.
func EqualItems ¶ added in v0.9.0
func EqualItems[T comparable](t testing.TB, one, two []T)
EqualItems compares the values in two slices and creates an error if all items are not equal.
func ErrorIs ¶
ErrorIs is an assertion form of errors.Is, and fails the test if the error (or its wrapped values) are not equal to the target error.
func Failing ¶
Failing asserts that the specified test fails. This was required for validating the behavior of the assertion, and may be useful in your own testing.
func MaxRuntime ¶ added in v0.8.2
MaxRuntime runs an operation and asserts that the operations runtime was less than the provided duration.
func MinRuntime ¶ added in v0.8.2
MinRuntime runs an operation and asserts that the operations runtime was greater than the provided duration.
func NotContains ¶
func NotContains[T comparable](t testing.TB, slice []T, item T)
Contains asserts that the item is *not* in the slice provided. If the input slice is empty, this assertion will never error.
func NotEqual ¶
func NotEqual[T comparable](t testing.TB, valOne, valTwo T)
NotEqual causes a test to fail if two (comparable) values are not equal. Be aware that pointers to objects (including objects passed as interfaces implemented by pointers) will pass this test, even if their values are equal.
func NotEqualItems ¶ added in v0.9.0
func NotEqualItems[T comparable](t testing.TB, one, two []T)
EqualItems compares the values in two slices and creates a failure if all items are not equal
func NotErrorIs ¶ added in v0.8.0
NotErrorIs is an assertion form of !errors.Is, and fails the test if the error (or its wrapped values) are equal to the target error.
func NotSubstring ¶
NotSubstring asserts that the substring is not present in the outer string.
func NotType ¶ added in v0.9.2
NotType fails the test when the type of the specifier matches the type of the object.
func NotZero ¶
func NotZero[T comparable](t testing.TB, val T)
NotZero fails a test if the value is the zero for its type.
func PanicValue ¶
func PanicValue[T comparable](t testing.TB, fn func(), value T)
PanicValue asserts that the function raises a panic and that the value, as returned by recover() is equal to the value provided.
func Type ¶ added in v0.9.2
Type fails the test if the type of the object doesn't match the specifier type provided.
func Zero ¶
func Zero[T comparable](t testing.TB, val T)
Zero fails a test if the value is not the zero-value for its type.
Types ¶
This section is empty.