Documentation ¶
Overview ¶
Package check contains two functions, which allow you to make fluent truth comparisons which t.Fail a test.
This is the preferred form for tests which need to check many conditions without necessarially failing the entire test on the first failed condition.
Example:
check.That(t, 10, should.Equal(20)) check.Loosely(t, myCustomInt(10), should.Equal(20))
The functions in check return a boolean value, and can be used to gate additional checks or asserts:
if check.That(t, 10, should.Equal(20)) { // additional logic/conditions/subtests if 10 == 20 }
This package has a sibling package `assert` which instead does t.FailNow, causing tests to immediately halt on the first error.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrIsLike ¶
ErrIsLike is a short helper to check that a given `err` matches a string or error `target`.
This is identical to:
check.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) (ok bool)
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: `check.Loosely(t, 10, should.Equal(20))`
Returns `true` iff `compare.CastCompare(actual)` returned no failure (i.e. nil)
func NoErr ¶
NoErr is a short helper to check that a given `err` is nil.
This is identical to:
check.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) (ok bool)
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: `check.That(t, 10, should.Equal(20))`
Returns `true` iff `compare(actual)` returned no failure (i.e. nil)
Types ¶
This section is empty.