shoulda

package module
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

README

shoulda

Go Reference

A Go testing library that shoulda be made as simple as possible, but not simpler.

You really shoulda not use it.

Documentation

Overview

Package shoulda provides an assertion library that is as simple as possible, but not simpler.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func BeDeepEqual

func BeDeepEqual(tb TB, actual, expected any) bool

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) bool

BeEqual checks that actual and expected are equal.

func BeFalse

func BeFalse(tb TB, actual bool) bool

BeFalse checks that actual is false.

func BeGreater

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

BeGreater checks that actual is greater than expected.

func BeLess

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

BeLess checks that actual is less than expected.

func BeNil

func BeNil(tb TB, actual any) bool

BeNil checks that actual is (untyped) nil.

func BeTrue

func BeTrue(tb TB, actual bool) bool

BeTrue checks that actual is true.

func BeZero

func BeZero[T cmp.Ordered](tb TB, actual T) bool

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) bool

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) bool

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) bool

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) bool

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

func Satisfy

func Satisfy[T any](tb TB, actual T, predicate func(_ T) bool) 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) 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 {
	Helper()
	Log(args ...any)
	Fail()
}

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

Directories

Path Synopsis
Package cmp provides types and functions related to comparing ordered values.
Package cmp provides types and functions related to comparing ordered values.
Package internal contains unstable code.
Package internal contains unstable code.
diffa
Package diffa provides a self-contained unified diff library that is as simple as possible, but not simpler.
Package diffa provides a self-contained unified diff library that is as simple as possible, but not simpler.
mustagen command
Package main generates the musta wrappers and mirrored tests.
Package main generates the musta wrappers and mirrored tests.
Package musta provides assertions that fail the test immediately.
Package musta provides assertions that fail the test immediately.