Documentation ¶
Overview ¶
Missing feature of the standard library: terse, expressive test assertions.
Index ¶
- func AnyEq[A any](act, exp A, opt ...any)
- func Cap[A ~[]B, B any](src A, exp int, opt ...any)
- 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 Equal[A any](act, exp A, opt ...any)
- func EqualSet[A ~[]B, B comparable](act, exp A, opt ...any)
- func Err(test func(error) bool, err error, opt ...any)
- func ErrAny(err error, opt ...any)
- func ErrIs(act, exp error, opt ...any)
- func ErrStr(exp string, err error, opt ...any)
- func Every[A ~[]B, B any](src A, fun func(B) bool, 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 Msg(msg, det string) string
- func MsgAB[A any](one, two A) string
- 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 MsgErr(err error) string
- func MsgErrActual(err error) string
- func MsgErrFunTest(fun func(), test func(error) bool) string
- func MsgErrIsMismatch(err, exp error) string
- func MsgErrMismatch(fun func(), test func(error) bool, err error) string
- func MsgErrMsgMismatch(fun func(), exp, act string) string
- func MsgErrNone(test func(error) bool) string
- func MsgErrTest(val func(error) bool) string
- func MsgExp[A any](val A) string
- func MsgExtra(src ...any) string
- func MsgFun(val func()) string
- func MsgFunErr(fun func(), err error) string
- func MsgLess[A any](one, two A) string
- func MsgLessEq[A any](one, two A) string
- func MsgNotEq[A any](act A) string
- func MsgNotPanic() string
- func MsgOpt(msg, det string) string
- func MsgPanicNoneWithErr(fun func(), exp error) string
- func MsgPanicNoneWithStr(fun func(), exp string) string
- func MsgPanicNoneWithTest(fun func(), test func(error) bool) string
- func MsgSingle[A any](val A) string
- func MsgSliceElem[A ~[]B, B any](src A, val B) string
- func MsgSliceElemMissing[A ~[]B, B any](src A, val B) string
- func MsgSliceElemUnexpected[A ~[]B, B any](src A, val B) string
- func Neg[A gg.Signed](src A, opt ...any)
- func NoErr(err error, opt ...any)
- func None[A ~[]B, B any](src A, fun func(B) bool, 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 NotPanic(fun func(), opt ...any)
- func NotSliceIs[A ~[]B, B any](act, nom A, opt ...any)
- func NotTextEq[A gg.Text](act, nom A, opt ...any)
- func NotTextHas[A, B gg.Text](src A, exp B, 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 Some[A ~[]B, B any](src A, fun func(B) bool, opt ...any)
- func Str[A any](src A, exp string, opt ...any)
- func TextEq[A gg.Text](act, exp A, 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 ErrMsgTest
- type VerbErr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnyEq ¶ added in v0.1.6
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 Cap ¶ added in v0.1.6
Asserts that the given slice has exactly the given capacity, or fails the test, printing the optional additional messages and the stack trace.
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 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 Err ¶
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 ErrAny ¶ added in v0.1.18
Asserts that the given error is non-nil, or fails the test, printing the optional additional messages and the stack trace.
func ErrIs ¶ added in v0.1.18
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 ErrStr ¶ added in v0.1.18
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 Every ¶ added in v0.1.12
Asserts that every element of the given slice satisfies the given predicate function, 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. Intended for interface values, maps, chans, funcs. For slices, use `SliceIs`.
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
Internal shortcut for generating parts of an error message.
func MsgEqInner ¶ added in v0.1.0
Internal shortcut for generating parts of an error message.
func MsgEqSimple ¶ added in v0.1.0
Internal shortcut for generating parts of an error message.
func MsgErrActual ¶ added in v0.1.18
Internal shortcut for generating parts of an error message.
func MsgErrFunTest ¶ added in v0.1.18
Internal shortcut for generating parts of an error message.
func MsgErrIsMismatch ¶ added in v0.1.18
Internal shortcut for generating parts of an error message.
func MsgErrMismatch ¶ added in v0.1.18
Internal shortcut for generating parts of an error message.
func MsgErrMsgMismatch ¶ added in v0.1.18
Internal shortcut for generating parts of an error message.
func MsgErrNone ¶ added in v0.1.18
Internal shortcut for generating parts of an error message.
func MsgErrTest ¶ added in v0.1.18
Internal shortcut for generating parts of an error message.
func MsgFun ¶ added in v0.1.18
func MsgFun(val func()) string
Internal shortcut for generating parts of an error message.
func MsgNotPanic ¶ added in v0.1.18
func MsgNotPanic() string
Internal shortcut for generating parts of an error message.
func MsgPanicNoneWithErr ¶ added in v0.1.18
Internal shortcut for generating parts of an error message.
func MsgPanicNoneWithStr ¶ added in v0.1.18
Internal shortcut for generating parts of an error message.
func MsgPanicNoneWithTest ¶ added in v0.1.18
Internal shortcut for generating parts of an error message.
func MsgSliceElem ¶ added in v0.1.18
Internal shortcut for generating parts of an error message.
func MsgSliceElemMissing ¶ added in v0.1.18
Internal shortcut for generating parts of an error message.
func MsgSliceElemUnexpected ¶ added in v0.1.18
Internal shortcut for generating parts of an error message.
func Neg ¶
Asserts that the given number is < 0, or fails the test, printing the optional additional messages and the stack trace.
func NoErr ¶ added in v0.1.18
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 None ¶ added in v0.1.12
Asserts that no elements of the given slice satisfy the given predicate function, or fails the test, printing 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. Intended for interface values, maps, chans, funcs. For slices, use `NotSliceIs`.
func NotPanic ¶ added in v0.1.6
func NotPanic(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 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 NotTextEq ¶ added in v0.1.6
Asserts that the inputs are not equal via `gg.TextEq`, or fails the test, printing the optional additional messages and the stack trace.
func NotTextHas ¶ added in v0.1.10
Asserts that the given chunk of text does not contain the given substring, or 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 Some ¶ added in v0.1.12
Asserts that at least one element of the given slice satisfies the given predicate function, or 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 TextEq ¶ added in v0.1.6
Asserts that the inputs are equal via `gg.TextEq`, 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 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.
type VerbErr ¶ added in v0.1.18
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 `VerbErr` 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.