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
- func Bool(cond bool, s ...string)
- func BoolT(t *testing.T, cond bool, s ...string)
- func Error(err error, s ...string)
- func ErrorEq(expected, actual error)
- func ErrorEqT(t *testing.T, expected, actual error)
- func ErrorT(t *testing.T, err error, s ...string)
- func NoError(err error, s ...string)
- func NoErrorT(t *testing.T, err error)
Variables ¶
var NoDebug bool
NoDebug can be set to true to cause all asserts to be ignored.
Functions ¶
func Bool ¶
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 ¶
BoolT checks a boolean condition, calling Fatal on t if it is false.
func Error ¶
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 ¶
ErrorEqT compares a pair of errors, calling Fatal on it if they don't match.
func ErrorT ¶
ErrorT asserts that err is not nil, e.g. asserting that an error has occurred. See also NoErrorT.
func NoError ¶
NoError asserts that err is nil, e.g. that no error has occurred.
func NoErrorT ¶
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.