assert

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package assert provides test assertion functions for verifying expected conditions in Go tests. It offers a cleaner alternative to manually writing if statements with t.Fatal or t.Error calls.

Use this package when writing unit tests that need to verify equality, check for errors, validate nil values, or confirm that code panics as expected. Assertions fail the test immediately by default, but can be configured to continue execution using the Continue option.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(t Testing, value any, check any, options ...Option)

Contains checks if an interface contains the contents of another. If the value is a string, it checks for a substring.

func Equals

func Equals(t Testing, first any, second any, options ...Option)

Equals checks if two values are equal.

func Error

func Error(t Testing, err error, options ...Option)

Error checks if an error occurred.

func ErrorExact

func ErrorExact(t Testing, err error, msg string, options ...Option)

ErrorExact checks if an error occurred with an exact message.

func ErrorPart

func ErrorPart(t Testing, err error, part string, options ...Option)

ErrorPart checks if an error occurred with a message containing a part.

func False

func False(t Testing, value bool, options ...Option)

False checks if a value is false.

func FloatEquals

func FloatEquals[T ~float64 | ~float32](t Testing, first T, second T, epsilon T, options ...Option)

FloatEquals checks if two floating point values are equal within a given epsilon.

func Nil

func Nil(t Testing, value any, options ...Option)

Nil checks if a value is nil.

func NoError

func NoError(t Testing, err error, options ...Option)

NoError checks if no error occurred.

func NotEquals

func NotEquals(t Testing, first any, second any, options ...Option)

NotEquals checks if two values are not equal.

func NotNil

func NotNil(t Testing, value any, options ...Option)

NotNil checks if a value is not nil.

func Panic

func Panic(t Testing, panicFunc func(), options ...Option)

Panic checks if a function panics.

func PanicExact

func PanicExact(t Testing, panicFunc func(), msg string, options ...Option)

PanicExact checks if a function panics with an exact message.

func PanicPart

func PanicPart(t Testing, panicFunc func(), part string, options ...Option)

PanicPart checks if a function panics with a message containing a part.

func True

func True(t Testing, value bool, options ...Option)

True checks if a value is true.

Types

type Option

type Option func(t *testContext)

Option modifies the configuration of testing.

func Continue

func Continue() Option

Continue marks the test as having failed but continues execution.

type Testing

type Testing interface {
	Helper()
	Error(args ...any)
	Fatal(args ...any)
}

Testing matches the functions on the testing.T struct.

Jump to

Keyboard shortcuts

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