assert

package
v0.0.0-...-678c4f2 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package assert contains two functions, which allow you to make fluent truth comparisons which t.FailNow a test.

Example:

assert.That(t, 10, should.Equal(20))
assert.Loosely(t, myCustomInt(10), should.Equal(20))

In the example above, the test case would halt immediately after the first `assert.That`, because 10 does not equal 20, and `assert.That` will call t.FailNow().

This package has a sibling package `check` which instead does t.Fail, allowing tests to make multiple checks without halting.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrIsLike

func ErrIsLike(t testing.TB, err error, target any)

ErrIsLike is a short helper to check that a given `err` matches a string or error `target`.

This is identical to:

assert.That(t, err, should.ErrLike(target))

See should.ErrLike.

func Loosely

func Loosely[T any](t truth.TestingTB, actual any, compare comparison.Func[T], opts ...truth.Option)

Loosely will compare `actual` using `compare.CastCompare(actual)`.

If this results in a failure.Summary, it will be reported with truth.Report, and the test will be failed with t.Fail().

Example: `assert.Loosely(t, 10, should.Equal(20))`

Returns `true` iff `compare.CastCompare(actual)` returned no failure (i.e. nil)

func NoErr

func NoErr(t testing.TB, err error)

NoErr is a short helper to check that a given `err` is nil.

This is identical to:

assert.That(t, err, should.ErrLike(nil))

See should.ErrLike.

func That

func That[T any](t truth.TestingTB, actual T, compare comparison.Func[T], opts ...truth.Option)

That will compare `actual` using `compare(actual)`.

If this results in a failure.Summary, it will be reported with truth.Report, and the test will be failed with t.Fail().

Example: `assert.That(t, 10, should.Equal(20))`

Returns `true` iff `compare(actual)` returned no failure (i.e. nil)

Types

This section is empty.

Jump to

Keyboard shortcuts

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