asserts

package module
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

README

Tideland Go Asserts

GitHub release GitHub license Go Module GoDoc

Description

Extensions to standard testing for easier assertions.

Contributors

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AboutEqual

func AboutEqual[T constraints.Integer | constraints.Float](t Tester, expected, actual T, delta T)

AboutEqual checks if the given values are equal within a delta.

func Different

func Different[T comparable](t Tester, expected, actual T)

Different checks if the given values are different. It uses the != operator for comparable types and is the opposite of Equal.

func Equal

func Equal[T comparable](t Tester, expected, actual T)

Equal checks if the given values are equal. It uses the == operator for comparable types.

func Error

func Error(t Tester, err error)

Error checks if the given error is not nil.

func ErrorContains

func ErrorContains(t Tester, err error, contains string)

ErrorContains checks if the given error is not nil and its message contains the expected substring.

func ErrorMatches

func ErrorMatches(t Tester, err error, pattern string)

ErrorMatches checks if the given error is not nil and its message matches the expected regular expression.

func Failed

func Failed(t Tester, count int) bool

Failed returns true if the given failed.

func Failf

func Failf(t Tester, format string, args ...interface{})

Failf is used to fail a test with a formatted message.

func False

func False(t Tester, condition bool)

False checks if the given condition is false. It's the opposite of True.

func IsError

func IsError(t Tester, expected, actual error)

IsError checks if the given error is not nil and of the expected type. It uses the errors.Is() function.

func Logf

func Logf(t Tester, format string, args ...interface{})

It's used to print additional information during testing. The location and function name are added automatically.

func MkPosNeg

func MkPosNeg(t *testing.T) (Tester, Tester)

MkPosNeg creates a positive and a negative tester.

func Nil

func Nil(t Tester, value any)

Nil checks if the given value is nil.

func NoError

func NoError(t Tester, err error)

NoError checks if the given error is nil. It's the opposite of Error.

func NotNil

func NotNil(t Tester, value any)

NotNil checks if the given value is not nil. It's the opposite of Nil.

func Range

func Range[T constraints.Integer | constraints.Float](t Tester, value, lower, upper T)

Range checks if the given value is within lower and upper bounds.

func True

func True(t Tester, condition bool)

True checks if the given condition is true.

Types

type Tester

type Tester interface {
	Logf(format string, args ...any)
	FailNow()
}

Tester defines the expected functions of any testing and logging type needed.

Jump to

Keyboard shortcuts

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