Documentation ¶
Overview ¶
Missing feature of the standard library: terse, expressive test assertions.
Index ¶
- func Catch(t testing.TB)
- func Empty[A ~[]B, B any](src A, opt ...any)
- func Eq[A comparable](act, exp A, opt ...any)
- func EqAny[A any](act, exp A, opt ...any)
- func Equal[A any](act, exp A, opt ...any)
- func EqualSet[A ~[]B, B comparable](act, exp A, opt ...any)
- func Error(test func(error) bool, err error, opt ...any)
- func ErrorAny(err error, opt ...any)
- func ErrorIs(exp, err error, opt ...any)
- func ErrorStr(exp string, err error, opt ...any)
- func False(val bool, opt ...any)
- func Has[A ~[]B, B comparable](src A, val B, opt ...any)
- func HasEqual[A ~[]B, B any](src A, val B, opt ...any)
- func HasEvery[A ~[]B, B comparable](src, exp A, opt ...any)
- func HasNone[A ~[]B, B comparable](src, exp A, opt ...any)
- func HasSome[A ~[]B, B comparable](src, exp A, opt ...any)
- func Is[A any](act, exp A, opt ...any)
- func Len[A ~[]B, B any](src A, exp int, opt ...any)
- func Less[A gg.Lesser[A]](one, two A, opt ...any)
- func LessEq[A interface{ ... }](one, two A, opt ...any)
- func LessEqPrim[A gg.LesserPrim](one, two A, opt ...any)
- func LessPrim[A gg.LesserPrim](one, two A, opt ...any)
- func MapNotEmpty[Src ~map[Key]Val, Key comparable, Val any](src Src, opt ...any)
- func MsgEq(act, exp any) string
- func MsgEqDetailed(act, exp any) string
- func MsgEqInner(act, exp any) string
- func MsgEqSimple(act, exp any) string
- func MsgNotEq[A any](act A) string
- func Neg[A gg.Signed](src A, opt ...any)
- func NoError(err error, opt ...any)
- func NoPanic(fun func(), opt ...any)
- func NotEmpty[A ~[]B, B any](src A, opt ...any)
- func NotEq[A comparable](act, nom A, opt ...any)
- func NotEqual[A any](act, nom A, opt ...any)
- func NotHas[A ~[]B, B comparable](src A, val B, opt ...any)
- func NotHasEqual[A ~[]B, B any](src A, val B, opt ...any)
- func NotIs[A any](act, exp A, opt ...any)
- func NotSliceIs[A ~[]B, B any](act, nom A, opt ...any)
- func NotZero[A any](val A, opt ...any)
- func Panic(test func(error) bool, fun func(), opt ...any)
- func PanicAny(fun func(), opt ...any)
- func PanicErrIs(exp error, fun func(), opt ...any)
- func PanicStr(exp string, fun func(), opt ...any)
- func Pos[A gg.Signed](src A, opt ...any)
- func SliceIs[A ~[]B, B any](act, exp A, opt ...any)
- func Str[A fmt.Stringer](src A, exp string, opt ...any)
- func TextHas[A, B gg.Text](src A, exp B, opt ...any)
- func TextLen[A gg.Text](src A, exp int, opt ...any)
- func True(val bool, opt ...any)
- func Uniq[A ~[]B, B comparable](src A, opt ...any)
- func Zero[A any](val A, opt ...any)
- type Err
- type ErrMsgTest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Catch ¶
Must be deferred. Usage:
func TestSomething(t *testing.T) { // Catches panics and uses `t.Fatalf`. defer gtest.Catch(t) // Test assertion. Panics and gets caught above. gtest.Eq(10, 20) }
func Empty ¶
Asserts that the given slice is empty, or fails the test, printing the optional additional messages and the stack trace.
func Eq ¶
func Eq[A comparable](act, exp A, opt ...any)
Asserts that the inputs are equal via `==`, or fails the test, printing the optional additional messages and the stack trace.
func EqAny ¶
Asserts that the inputs are equal via `==`, or fails the test, printing the optional additional messages and the stack trace. Doesn't statically require the inputs to be comparable, but may panic if they aren't.
func Equal ¶
Asserts that the inputs are deeply equal, or fails the test, printing the optional additional messages and the stack trace.
func EqualSet ¶
func EqualSet[A ~[]B, B comparable](act, exp A, opt ...any)
Asserts that the input slices have the same set of elements, or fails the test, printing the optional additional messages and the stack trace.
func Error ¶
Asserts that the given error is non-nil AND satisfies the given error-testing function. Otherwise fails the test, printing the optional additional messages and the stack trace.
func ErrorAny ¶
Asserts that the given error is non-nil, or fails the test, printing the optional additional messages and the stack trace.
func ErrorIs ¶ added in v0.0.14
Asserts that the given error is non-nil and matches the expected error via `errors.Is`, or fails the test, printing the optional additional messages and the stack trace.
func ErrorStr ¶ added in v0.0.10
Asserts that the given error is non-nil and its message contains the given substring, or fails the test, printing the optional additional messages and the stack trace.
func False ¶
Asserts that the input is `false`, or fails the test, printing the optional additional messages and the stack trace.
func Has ¶
func Has[A ~[]B, B comparable](src A, val B, opt ...any)
Asserts that the given slice contains the given value, or fails the test, printing the optional additional messages and the stack trace.
func HasEqual ¶ added in v0.1.0
Asserts that the given slice contains the given value, or fails the test, printing the optional additional messages and the stack trace. Uses `gg.Equal` to compare values. For values that implement `comparable`, use `Has` which is simpler and faster.
func HasEvery ¶ added in v0.0.5
func HasEvery[A ~[]B, B comparable](src, exp A, opt ...any)
Asserts that the first slice contains all elements from the second slice. In other words, asserts that the first slice is a strict superset of the second. Otherwise fails the test, printing the optional additional messages and the stack trace.
func HasNone ¶
func HasNone[A ~[]B, B comparable](src, exp A, opt ...any)
Asserts that the first slice does not contain any from the second slice. In other words, asserts that the element sets are disjoint. Otherwise fails the test, printing the optional additional messages and the stack trace.
func HasSome ¶ added in v0.0.5
func HasSome[A ~[]B, B comparable](src, exp A, opt ...any)
Asserts that the first slice contains some elements from the second slice. In other words, asserts that the element sets have an intersection. Otherwise fails the test, printing the optional additional messages and the stack trace.
func Is ¶ added in v0.1.0
Asserts that the inputs are byte-for-byte identical, via `gg.Is`. Otherwise fails the test, printing the optional additional messages and the stack trace.
func Len ¶
Asserts that the given slice has exactly the given length, or fails the test, printing the optional additional messages and the stack trace.
func Less ¶
Asserts `one < two`, or fails the test, printing the optional additional messages and the stack trace. For primitives, see `LessPrim`.
func LessEq ¶
func LessEq[A interface { gg.Lesser[A] comparable }](one, two A, opt ...any)
Asserts `one <= two`, or fails the test, printing the optional additional messages and the stack trace. For primitives, see `LessEqPrim`. Also see `Less`.
func LessEqPrim ¶
func LessEqPrim[A gg.LesserPrim](one, two A, opt ...any)
Asserts `one <= two`, or fails the test, printing the optional additional messages and the stack trace. For non-primitives that implement `gg.Lesser`, see `LessEq`. Also see `LessPrim`.
func LessPrim ¶
func LessPrim[A gg.LesserPrim](one, two A, opt ...any)
Asserts `one < two`, or fails the test, printing the optional additional messages and the stack trace. For non-primitives that implement `gg.Lesser`, see `Less`. Also see `LessEqPrim`.
func MapNotEmpty ¶
func MapNotEmpty[Src ~map[Key]Val, Key comparable, Val any](src Src, opt ...any)
Asserts that the given slice is not empty, or fails the test, printing the optional additional messages and the stack trace.
func MsgEqDetailed ¶ added in v0.1.0
func MsgEqInner ¶ added in v0.1.0
Used internally when generating error messages about failed equality.
func MsgEqSimple ¶ added in v0.1.0
func Neg ¶
Asserts that the given number is < 0, or fails the test, printing the optional additional messages and the stack trace.
func NoError ¶
Asserts that the given error is nil, or fails the test, printing the error's trace if possible, the optional additional messages, and the stack trace.
func NoPanic ¶
func NoPanic(fun func(), opt ...any)
Asserts that the given function doesn't panic, or fails the test, printing the error's trace if possible, the optional additional messages, and the stack trace.
func NotEmpty ¶
Asserts that the given slice is not empty, or fails the test, printing the optional additional messages and the stack trace.
func NotEq ¶
func NotEq[A comparable](act, nom A, opt ...any)
Asserts that the inputs are not equal via `!=`, or fails the test, printing the optional additional messages and the stack trace.
func NotEqual ¶
Asserts that the inputs are not deeply equal, or fails the test, printing the optional additional messages and the stack trace.
func NotHas ¶
func NotHas[A ~[]B, B comparable](src A, val B, opt ...any)
Asserts that the given slice does not contain the given value, or fails the test, printing the optional additional messages and the stack trace.
func NotHasEqual ¶ added in v0.1.0
Asserts that the given slice does not contain the given value, or fails the test, printing the optional additional messages and the stack trace. Uses `gg.Equal` to compare values. For values that implement `comparable`, use `HasNot` which is simpler and faster.
func NotIs ¶ added in v0.1.0
Asserts that the inputs are NOT byte-for-byte identical, via `gg.Is`. Otherwise fails the test, printing the optional additional messages and the stack trace.
func NotSliceIs ¶ added in v0.0.2
Asserts that the given slice headers (not their elements) are distinct. This means at least one of the following fields is different: data pointer, length, capacity. Does NOT compare individual elements, unlike `NotEqual`. Otherwise fails the test, printing the optional additional messages and the stack trace.
func NotZero ¶
Asserts that the input is zero via `gg.IsZero`, or fails the test, printing the optional additional messages and the stack trace.
func Panic ¶
Asserts that the given function panics AND that the resulting error satisfies the given error-testing function. Otherwise fails the test, printing the optional additional messages and the stack trace.
func PanicAny ¶
func PanicAny(fun func(), opt ...any)
Asserts that the given function panics, or fails the test, printing the optional additional messages and the stack trace.
func PanicErrIs ¶ added in v0.0.13
Asserts that the given function panics and the panic result matches the given error via `errors.Is`, or fails the test, printing the optional additional messages and the stack trace.
func PanicStr ¶
Asserts that the given function panics with an error whose message contains the given substring, or fails the test, printing the optional additional messages and the stack trace.
func Pos ¶
Asserts that the given number is > 0, or fails the test, printing the optional additional messages and the stack trace.
func SliceIs ¶ added in v0.0.2
Asserts that the given slice headers (not their elements) are equal via `gg.SliceIs`. This means they have the same data pointer, length, capacity. Does NOT compare individual elements, unlike `Equal`. Otherwise fails the test, printing the optional additional messages and the stack trace.
func Str ¶
Asserts that `.String` of the input matches the expected string, or fails the test, printing the optional additional messages and the stack trace.
func TextHas ¶
Asserts that the given chunk of text contains the given substring, or fails the test, printing the optional additional messages and the stack trace.
func TextLen ¶
Asserts that the given text has exactly the given length, or fails the test, printing the optional additional messages and the stack trace.
func True ¶
Asserts that the input is `true`, or fails the test, printing the optional additional messages and the stack trace.
func Uniq ¶
func Uniq[A ~[]B, B comparable](src A, opt ...any)
Asserts that the given slice contains no duplicates, or fails the test, printing the optional additional messages and the stack trace.
Types ¶
type Err ¶
Used internally by assertion utils. Error wrapper whose default stringing uses "%+v" formatting on the inner error, causing it to be ALWAYS formatted with a stack trace, which is useful when panics are not caught.
func ErrAt ¶ added in v0.1.3
Shortcut for generating a test error (of type `Err` provided by this package) with the given message, skipping the given amount of stack frames.
func ErrLines ¶ added in v0.1.3
Shortcut for generating an error where the given messages are combined as lines.
type ErrMsgTest ¶
type ErrMsgTest string
Shortcut for error testing.
func (ErrMsgTest) Is ¶
func (self ErrMsgTest) Is(err error) bool
Tests that the given error has the given message.