assert

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// The failure format string for values not being equal. Formatted with `expected` then `got`.
	EqualMessage = "value did not equal expectation.\nexpected: %v\n     got: %v"

	// The error format string for one or both pointers being nil. Formatted with `got` then `expected`.
	DereferenceEqualErrMsg = "could not dereference nil pointer\ngot %v, expected %v"

	// The failure format string if the err is not nil. Formatted with `err`.
	NilErrMessage = "expected no error, got error:\n%v"

	// The failure format string if the err is nil.
	NotNilErrMesage = "expected an error, got nil"

	// The failure format string for slices being different sizes. Formatted with `expected` then `got`.
	SliceSizeMessage = "slices were different sizes.\nexpected len:%d\n     got len:%d\n"

	// The failure format string for slices not matching at some index. Formatted with the mismatched
	// index, then `expected`, then `got`.
	SliceMismatchMessage = "slices differed at index %d.\nexpected: %v\n     got: %v"
)

Functions

func Assert

func Assert(t TestingT, condition bool, message string, args ...any)

Assert that the passed condition is true. If not, fatally fail with `message` and format `args` into it.

func DereferenceEqual

func DereferenceEqual[T comparable](t TestingT, expected *T, got *T)

Assert that the value at `got` equals the value at `expected`. Will error if either pointer is nil. Uses `assert.DereferenceEqualErrMsg` and `assert.EqualMessage`.

func DereferenceEqualMsg

func DereferenceEqualMsg[T comparable](
	t TestingT,
	expected *T,
	got *T,
	errMessage,
	mismatchMessage string,
)

Assert that the value at `got` equals the value at `expected`. Will error if either pointer is nil. Uses `errMessage` and `mismatchMessage`.

func Equal

func Equal[T comparable](t TestingT, expected T, got T)

Assert that `got` equals `expected`. The types between compared arguments must be the same. Uses `assert.EqualMessage`.

func EqualMsg

func EqualMsg[T comparable](t TestingT, expected T, got T, message string)

Assert that `got` equals `expected`. The types between compared arguments must be the same. Uses `message`.

func NilErr

func NilErr(t TestingT, err error)

Assert that that `err` is nil. Uses `assert.NilErrMessage`.

func NotNilErr added in v0.12.0

func NotNilErr(t TestingT, err error)

Assert that that `err` is not nil. Uses `assert.NotNillErrMesage`.

func SliceEqual

func SliceEqual[T comparable](t TestingT, expected []T, got []T)

Assert that slices `got` and `expected` are equal. Will produce a different message if the lengths are different or if any element mismatches. Uses `assert.SliceSizeMessage` and `assert.SliceMismatchMessage`.

func SliceEqualMsg

func SliceEqualMsg[T comparable](
	t TestingT,
	expected []T,
	got []T,
	sizeMessage, mismatchMessage string,
)

Assert that slices `got` and `expected` are equal. Will produce a different message if the lengths are different or if any element mismatches. Uses `sizeMessage` and `mismatchMessage`.

Types

type TestingT

type TestingT interface {
	Helper()
	Fatal(...any)
	Fatalf(string, ...any)
	Errorf(string, ...any)
}

The interface that represents the subset of `testing.T` that this package requires. Passing in a `testing.T` satisfies this interface.

Jump to

Keyboard shortcuts

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