assert

package
v0.0.0-...-cdb6528 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package assert helps writing assertions for tests. Benefits include brevity, clarity, and helpful error messages.

If .T(t) is specified, failures are reported with t.Error which means multiple errors may be reported. If .T(t) is not specified, panic is called with the error string.

For example:

assert.That(a || b)
assert.This(x).Is(y)
assert.T(t).This(x).Like(y)
assert.Msg("first time").That(a || b)
assert.T(t).Msg("second").This(fn).Panics("illegal")

Use a variable to avoid specifying .T(t) repeatedly:

assert := assert.T(t)
assert.This(x).Is(y)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Catch

func Catch(f func()) (result any)

Catch calls the given function, catching and returning panics

func False

func False(b bool)

False gives an error if the value is not true. False(x) is the same as That(!x)

func Is

func Is(actual, expected any) bool

func Msg

func Msg(args ...any) assert

Msg adds additional information to print with the error. It can be useful with That/True/False where the error is not very helpful.

func Nil

func Nil(v any)

Nil gives an error if the value is not nil. It handles nil func/pointer/slice/map/channel using reflect.IsNil For performance critical code, consider using That(value == nil)

func ShouldNotReachHere

func ShouldNotReachHere() int

func T

func T(t *testing.T) assert

T specifies a *testing.T to use for reporting errors

func That

func That(cond bool)

That gives an error if the value is not true. That(x) is the same as True(x)

func This

func This(v any) value

This sets a value to be compared e.g. with Is or Like

func True

func True(b bool)

True gives an error if the value is not true. True(x) is the same as That(x)

Types

This section is empty.

Jump to

Keyboard shortcuts

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