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 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 NotContains[T comparable](t testing.TB, slice []T, item T)
- func NotEqual[T comparable](t testing.TB, valOne, valTwo T)
- func NotError(t testing.TB, err error)
- func NotPanic(t testing.TB, fn func())
- func NotSubstring(t testing.TB, str, substr string)
- 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 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 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 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 NotSubstring ¶
NotSubstring asserts that the substring is not present in the outer string.
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 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.