| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
This package is not in the latest version of its module.
Go to latest Published: Aug 22, 2026 License: MITThe Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Modules with tagged versions give importers more predictable builds.
When a project reaches major version v1 it is considered stable.
Package assert provides utilities to assert conditions in tests.
Assertion functions return a boolean value indicating whether the assertion succeeded.
By default, assertion failures are reported using testing.TB.Fatal. This can be customized with the Report() option.
This section is empty.
var DeepEqualer atomicutil.Value[func(v1, v2 any) (string, bool)]
DeepEqualer is a function that checks if two values are deeply equal.
By default, it uses compare.DefaultComparator.
var DefaultReport atomicutil.Value[ReportFunc]
DefaultReport is the default ReportFunc used for assertion failures. See the Report option.
By default it uses testing.TB.Fatal.
var DefaultShowStack atomic.Bool
DefaultShowStack is the default value used to show stack traces on assertion failures. See the ShowStack option.
By default it is true.
var ValueStringer atomicutil.Value[func(any) string]
ValueStringer is a function that returns the string representation of a value.
By default, it uses pretty.String.
AllocsPerRun asserts that a function allocates a certain number of times per run.
If the race detector is enabled, this function does nothing and returns true. This prevents tests from failing due to the increased number of allocations.
BytesContains asserts that b contains subslice. It uses bytes.Contains to check if subslice is contained in b.
BytesEqual asserts that b1 and b2 are equal. It uses bytes.Equal to compare the two byte slices.
BytesEqualFold asserts that b1 and b2 are equal, ignoring case. It uses bytes.EqualFold to compare the two byte slices.
BytesHasPrefix asserts that b begins with prefix. It uses bytes.HasPrefix to check if b begins with prefix.
BytesHasSuffix asserts that b ends with suffix. It uses bytes.HasSuffix to check if b ends with suffix.
BytesNotContains asserts that b does not contain subslice. It uses bytes.Contains to check if subslice is contained in b.
BytesNotEqual asserts that b1 and b2 are not equal. It uses bytes.Equal to compare the two byte slices.
BytesNotEqualFold asserts that b1 and b2 are not equal, ignoring case. It uses bytes.EqualFold to compare the two byte slices.
BytesNotHasPrefix asserts that b does not begin with prefix. It uses bytes.HasPrefix to check if b begins with prefix.
BytesNotHasSuffix asserts that b does not end with suffix. It uses bytes.HasSuffix to check if b ends with suffix.
ChanNotEmpty asserts that c is not empty.
ChanNotNil asserts that c is not nil.
ChanRecvEmpty asserts that c is empty.
ChanRecvLen asserts that c has length l.
ChanRecvNil asserts that c is nil.
ChanRecvNotEmpty asserts that c is not empty.
ChanRecvNotNil asserts that c is not nil.
ChanSendEmpty asserts that c is empty.
ChanSendLen asserts that c has length l.
ChanSendNil asserts that c is nil.
ChanSendNotEmpty asserts that c is not empty.
ChanSendNotNil asserts that c is not nil.
DeepEqual asserts that v1 and v2 are deeply equal according to DeepEqualer.
func Equal[T comparable](tb testing.TB, v1, v2 T, opts ...Option) bool
Equal asserts that v1 == v2.
For floating-point values, note that NaN != NaN, so Equal will always fail when comparing NaN to itself. Use FloatNaN or FloatNotNaN instead.
ErrorAs asserts that errors.As returns true.
target must be a non-nil pointer to a type that implements error, or to any interface type.
ErrorAsType asserts that errors.AsType returns true and returns the error of type E.
ErrorContains asserts that the result of [error.Error] contains substr.
ErrorEqual asserts that the result of [error.Error] is equal to message.
ErrorNotIs asserts that errors.Is returns false.
Fail handles assertion failure. It calls the ReportFunc with the given message.
FloatInf asserts that f is an infinity according to sign. If sign > 0, asserts that f is positive infinity. If sign < 0, asserts that f is negative infinity. If sign == 0, asserts that f is either positive or negative infinity.
FloatNotInf asserts that f is not an infinity according to sign. If sign > 0, asserts that f is not positive infinity. If sign < 0, asserts that f is not negative infinity. If sign == 0, asserts that f is not any infinity (finite value).
FloatNotNaN asserts that f is not NaN (not-a-number).
GreaterOrEqual asserts that v1 >= v2.
LessOrEqual asserts that v1 <= v2.
func MapEqual[M1, M2 ~map[K]V, K, V comparable](tb testing.TB, m1 M1, m2 M2, opts ...Option) bool
MapEqual asserts that m1 and m2 are equal.
MapNotEmpty asserts that m is not empty.
func MapNotEqual[M1, M2 ~map[K]V, K, V comparable](tb testing.TB, m1 M1, m2 M2, opts ...Option) bool
MapNotEqual asserts that m1 and m2 are not equal.
func Negative[T SignedNumber](tb testing.TB, v T, opts ...Option) bool
Negative asserts that the value is negative.
func NewDeepEqualerWithComparator(cr *compare.Comparator) func(v1, v2 any) (string, bool)
NewDeepEqualerWithComparator creates a new DeepEqualer with a custom compare.Comparator.
NotDeepEqual asserts that v1 and v2 are not deeply equal according to DeepEqualer.
func NotEqual[T comparable](tb testing.TB, v1, v2 T, opts ...Option) bool
NotEqual asserts that v1 != v2.
NotPanics asserts that the code inside the function f does not panic.
It returns true if no panic occurred, or false if f panicked.
func NotZero[T comparable](tb testing.TB, v T, opts ...Option) bool
NotZero asserts that v != zero.
Panics asserts that the code inside the function f panics.
It returns the recovered value and true if a panic occurred, or nil and false if f did not panic.
func Positive[T SignedNumber](tb testing.TB, v T, opts ...Option) bool
Positive asserts that the value is positive.
RegexpMatch asserts that rs matches s.
RegexpNotMatch asserts that rs doesn't match s.
func SliceContains[S ~[]E, E comparable](tb testing.TB, s S, v E, opts ...Option) bool
SliceContains asserts that s contains v.
func SliceElementsMatch[S ~[]E, E comparable](tb testing.TB, s1, s2 S, opts ...Option) bool
SliceElementsMatch asserts that s1 and s2 contain the same elements, regardless of order.
SliceEmpty asserts that s is empty.
func SliceEqual[S ~[]E, E comparable](tb testing.TB, s1, s2 S, opts ...Option) bool
SliceEqual asserts that s1 and s2 are equal.
func SliceNotContains[S ~[]E, E comparable](tb testing.TB, s S, v E, opts ...Option) bool
SliceNotContains asserts that s does not contain v.
SliceNotEmpty asserts that s is not empty.
func SliceNotEqual[S ~[]E, E comparable](tb testing.TB, s1, s2 S, opts ...Option) bool
SliceNotEqual asserts that s1 and s2 are not equal.
SliceNotNil asserts that s is not nil.
StringContains asserts that s contains substr.
StringEqualFold asserts that s1 and s2 are equal, ignoring case.
StringHasPrefix asserts that s begins with prefix.
StringHasSuffix asserts that s ends with suffix.
StringNotContains asserts that s does not contain substr.
StringNotHasPrefix asserts that s does not begin with prefix.
StringNotHasSuffix asserts that s does not end with suffix.
func Zero[T comparable](tb testing.TB, v T, opts ...Option) bool
Zero asserts that v == zero.
type Option func(*options)
Option is an option for an assertion.
Lazy returns an Option that defers the evaluation of the option.
It helps to reduce allocations when the option is not used.
MessageTransform returns an Option that adds a message transform function. The function is called before the ReportFunc. If several functions are added, they are called in order.
MessageWrap returns an Option that wraps the message. The final message is "<msg>: <original message>".
MessageWrapf returns an Option that wraps the message. The final message is "<format msg>: <original message>".
func Report(f ReportFunc) Option
Report returns an Option that sets the ReportFunc. The default value is DefaultReport.
func ReportError() Option
ReportError returns an Option that sets the ReportFunc to testing.TB.Error.
func ReportFatal() Option
ReportFatal returns an Option that sets the ReportFunc to testing.TB.Fatal.
func ReportLog() Option
ReportLog returns an Option that sets the ReportFunc to testing.TB.Log.
func ReportSkip() Option
ReportSkip returns an Option that sets the ReportFunc to testing.TB.Skip.
RegexpString is a type that can be either a *regexp.Regexp or a string.
If it's a string, it's automatically compiled to a *regexp.Regexp.
ReportFunc is a function that is called when an assertion fails.
It can be set to method expressions such as testing.TB.Fatal, testing.TB.Error, testing.TB.Skip, or testing.TB.Log. The default value is DefaultReport.
| Path | Synopsis |
|---|---|
|
Package assertauto provides helpers to automatically update the expected values of test assertions.
|
Package assertauto provides helpers to automatically update the expected values of test assertions. |
|
internal
Package diff is a copy of https://pkg.go.dev/internal/diff.
|
Package diff is a copy of https://pkg.go.dev/internal/diff. |
|
Package asserttest provides utilities to test assertions.
|
Package asserttest provides utilities to test assertions. |
| Back | FazBrowse Home | New Git URL |