Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

README.md

2.66 Kb · 75 lines

v0 - Unaudited This is an initial version of this package that has not yet been formally audited. A fully audited version will be published as a subsequent release. Use in production at your own risk.

urequire - fail-fast test assertions

Sister package to uassert. Same assertions, but each one calls t.FailNow() on failure so the test stops immediately instead of continuing.

Usage

 1import (
 2    "testing"
 3
 4    "gno.land/p/nt/urequire/v0"
 5)
 6
 7func TestPipeline(t *testing.T) {
 8    out, err := Build()
 9    urequire.NoError(t, err)        // aborts the test if Build failed
10    urequire.NotNil(t, out)         // out is safe to dereference below
11    urequire.Equal(t, "ready", out.Status)
12}

API

Helpers take uassert.TestingT and return nothing — they either pass or stop the test.

Equality and emptiness:

1func Equal(t uassert.TestingT, expected, actual any, msgs ...string)
2func NotEqual(t uassert.TestingT, expected, actual any, msgs ...string)
3func Empty(t uassert.TestingT, obj any, msgs ...string)
4func NotEmpty(t uassert.TestingT, obj any, msgs ...string)

Truthiness and nil:

1func True(t uassert.TestingT, value bool, msgs ...string)
2func False(t uassert.TestingT, value bool, msgs ...string)
3func Nil(t uassert.TestingT, value any, msgs ...string)
4func NotNil(t uassert.TestingT, value any, msgs ...string)
5func TypedNil(t uassert.TestingT, value any, msgs ...string)
6func NotTypedNil(t uassert.TestingT, value any, msgs ...string)

Errors:

1func NoError(t uassert.TestingT, err error, msgs ...string)
2func Error(t uassert.TestingT, err error, msgs ...string)
3func ErrorContains(t uassert.TestingT, err error, contains string, msgs ...string)
4func ErrorIs(t uassert.TestingT, err, target error, msgs ...string)

Panics and aborts (f may be func() or func(realm); pass the test's own cur as rlm):

1func PanicsWithMessage(t uassert.TestingT, rlm realm, msg string, f any, msgs ...string)
2func PanicsContains(t uassert.TestingT, rlm realm, substr string, f any, msgs ...string)
3func NotPanics(t uassert.TestingT, rlm realm, f any, msgs ...string)
4func AbortsWithMessage(t uassert.TestingT, rlm realm, msg string, f any, msgs ...string)
5func AbortsContains(t uassert.TestingT, rlm realm, substr string, f any, msgs ...string)
6func NotAborts(t uassert.TestingT, rlm realm, f any, msgs ...string)

Notes

  • Use urequire when the rest of the test depends on the assertion holding (e.g. a nil check before dereferencing). Use uassert when you want to collect multiple failures from the same test run.
  • Each urequire helper is a thin wrapper that calls the matching uassert helper and then t.FailNow() on failure.