musta

package
v0.0.0-...-3f1a620 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: BSD-2-Clause Imports: 4 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 deeply equal.

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.

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.

func BeLess

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

BeLess checks that actual is less than expected.

func BeNil

func BeNil(tb TB, actual any)

BeNil 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 cmp.Ordered](tb TB, actual T)

BeZero 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 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 (Method_expression)
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 interface {
	shoulda.TB
	FailNow()
}

TB is a subset of testing.TB that is sufficient for assertions.

Jump to

Keyboard shortcuts

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