assert

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2020 License: ISC Imports: 5 Imported by: 0

Documentation

Overview

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

Constants

This section is empty.

Variables

View Source
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.

Types

This section is empty.

Jump to

Keyboard shortcuts

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