musta

package
v0.0.0-...-28d173c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2026 License: BSD-2-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package musta provides assertions that fail the test immediately.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func BeDeepEqual

func BeDeepEqual(tb TB, actual, expected any)

BeDeepEqual checks that actual and expected are equal according to reflect.DeepEqual.

Example
BeDeepEqual(t, []int{13}, []int64{13})
Output:
Values are not deep equal:
actual:   []int{13}
expected: []int64{13}
FAIL

func BeEqual

func BeEqual[T cmp.Ordered](tb TB, actual, expected T)

BeEqual checks that actual and expected are equal according to cmp.Equal.

func BeFalse

func BeFalse(tb TB, actual bool)

BeFalse checks that actual is false.

func BeGreater

func BeGreater[T cmp.Ordered](tb TB, actual, expected T)

BeGreater checks that actual is greater than expected according to cmp.Greater.

func BeLess

func BeLess[T cmp.Ordered](tb TB, actual, expected T)

BeLess checks that actual is less than expected according to cmp.Less.

func BeNil

func BeNil(tb TB, actual any)

BeNil checks that actual is untyped nil.

func BeNilf

func BeNilf(tb TB, actual any, msg string, args ...any)

BeNilf checks that actual is untyped nil.

func BeTrue

func BeTrue(tb TB, actual bool)

BeTrue checks that actual is true.

func BeZero

func BeZero[T comparable](tb TB, actual T)

BeZero checks that actual is the zero value of its type.

func BeZerof

func BeZerof[T comparable](tb TB, actual T, msg string, args ...any)

BeZerof checks that actual is the zero value of its type.

func CompareEqual

func CompareEqual[T any](tb TB, actual, expected T, compare func(_, _ T) int)

CompareEqual checks that compare(actual, expected) returns 0 (cmp.OrderEqual).

func CompareGreater

func CompareGreater[T any](tb TB, actual, expected T, compare func(_, _ T) int)

CompareGreater checks that compare(actual, expected) returns 1 (cmp.OrderGreater).

func CompareLess

func CompareLess[T any](tb TB, actual, expected T, compare func(_, _ T) int)

CompareLess checks that compare(actual, expected) returns -1 (cmp.OrderLess).

func CompareWith

func CompareWith[T any](tb TB, actual, expected T, order cmp.Order, compare func(_, _ T) int)

CompareWith checks that compare(actual, expected) returns order.

func NotBeDeepEqual

func NotBeDeepEqual(tb TB, actual, expected any)

NotBeDeepEqual checks that actual and expected are not equal according to reflect.DeepEqual.

Example

ExampleNotBeDeepEqual demonstrates NotBeDeepEqual.

NotBeDeepEqual(t, []int{13}, []int{13})
Output:
Values are deep equal:
actual:   []int{13}
expected: []int{13}
FAIL

func NotBeNil

func NotBeNil(tb TB, actual any)

NotBeNil checks that actual is not (untyped) nil.

func NotBeNilf

func NotBeNilf(tb TB, actual any, msg string, args ...any)

NotBeNilf checks that actual is not (untyped) nil.

func NotBeZero

func NotBeZero[T comparable](tb TB, actual T)

NotBeZero checks that actual is not the zero value of its type.

func NotBeZerof

func NotBeZerof[T comparable](tb TB, actual T, msg string, args ...any)

NotBeZerof checks that actual is not the zero value of its type.

func Satisfy

func Satisfy[T any](tb TB, actual T, predicate func(_ T) bool)

Satisfy checks that predicate returns true for actual.

Example (Inline)
Satisfy(t, 13, func(v int) bool { return v > 42 })
Output:
predicate is not satisfied for
actual:   13
FAIL
Example (MethodExpression)
actual := time.Date(2026, time.April, 9, 17, 32, 42, 123, time.UTC)
Satisfy(t, actual, time.Time.IsZero)
Output:
predicate is not satisfied for
actual:   2026-04-09 17:32:42.000000123 +0000 UTC
FAIL
Example (MethodValue)
actual := time.Date(2026, time.April, 9, 17, 32, 42, 123, time.UTC)
Satisfy(t, actual, time.Now().Before)
Output:
predicate is not satisfied for
actual:   2026-04-09 17:32:42.000000123 +0000 UTC
FAIL

func SatisfyWith

func SatisfyWith[T any](tb TB, actual, expected T, predicate func(_, _ T) bool)

SatisfyWith checks that predicate returns true for actual and expected.

Example (Function)
SatisfyWith(t, 13, 42, cmp.Greater)
Output:
predicate is not satisfied with
actual:   13
expected: 42
FAIL
Example (Inline)
SatisfyWith(t, 13, 42, func(x, y int) bool { return x > y })
Output:
predicate is not satisfied with
actual:   13
expected: 42
FAIL
Example (MethodExpression)
actual := time.Date(2026, time.April, 9, 17, 32, 42, 123, time.UTC)
expected := time.Date(2026, time.April, 9, 17, 32, 42, 123, time.FixedZone("My", 4*int(time.Hour.Seconds())))
SatisfyWith(t, actual, expected, time.Time.Before)
Output:
predicate is not satisfied with
actual:   2026-04-09 17:32:42.000000123 +0000 UTC
expected: 2026-04-09 17:32:42.000000123 +0400 My
FAIL

Types

type TB

type TB = shoulda.TB

TB is a subset of testing.TB that is used by this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL