package assert

import "git.wntrmute.dev/kyle/goutils/assert"

Package assert provides C-like assertions for Go. For more information, see assert(3) (e.g. `man 3 assert`).

The T variants operating on *testing.T values; instead of killing the program, they call the Fatal method.

If GOTRACEBACK is set to enable coredumps, assertions will generate coredumps.

Index

Variables

var NoDebug bool

NoDebug can be set to true to cause all asserts to be ignored.

Functions

func Bool

func Bool(cond bool, s ...string)

Bool asserts that cond is false.

For example, this would replace

if x < 0 {
        log.Fatal("x is subzero")
}

The same assertion would be

assert.Bool(x, "x is subzero")

func BoolT

func BoolT(t *testing.T, cond bool, s ...string)

BoolT checks a boolean condition, calling Fatal on t if it is false.

func Error

func Error(err error, s ...string)

Error asserts that err is not nil, e.g. that an error has occurred.

For example,

if err == nil {
        log.Fatal("call to <something> should have failed")
}
// becomes
assert.Error(err, "call to <something> should have failed")

func ErrorEq

func ErrorEq(expected, actual error)

ErrorEq asserts that the actual error is the expected error.

func ErrorEqT

func ErrorEqT(t *testing.T, expected, actual error)

ErrorEqT compares a pair of errors, calling Fatal on it if they don't match.

func ErrorT

func ErrorT(t *testing.T, err error, s ...string)

ErrorT asserts that err is not nil, e.g. asserting that an error has occurred. See also NoErrorT.

func NoError

func NoError(err error, s ...string)

NoError asserts that err is nil, e.g. that no error has occurred.

func NoErrorT

func NoErrorT(t *testing.T, err error)

NoErrorT asserts that err is nil, e.g. asserting that no error has occurred. See also ErrorT.

Source Files

assert.go

Version
v1.7.7 (latest)
Published
Jun 15, 2024
Platform
linux/amd64
Imports
5 packages
Last checked
4 days ago

Tools for package owners.