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

v0 source pure

v0 - Unaudited: This is an initial version that has not yet been formally audited. A fully audited version will be pu...

Readme View source

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.

Overview

v0 - Unaudited: This is an initial version 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.

Package urequire provides test assertion functions that immediately fail the test on error, complementing the uassert package.

urequire is a sister package for uassert. XXX: codegen the package.

Functions 20

func AbortsContains

1func AbortsContains(t uassert.TestingT, rlm realm, substr string, f any, msgs ...string)
source

AbortsContains requires that the code inside the specified func aborts (panics when crossing another realm) and the abort message contains the specified substring. See uassert.AbortsWithMessage for `rlm` semantics.

func AbortsWithMessage

1func AbortsWithMessage(t uassert.TestingT, rlm realm, msg string, f any, msgs ...string)
source

AbortsWithMessage requires that the code inside the specified func aborts (panics when crossing another realm). Use PanicsWithMessage for requiring local panics within the same realm. Note: This relies on gno's `revive` mechanism to catch aborts. See uassert.AbortsWithMessage for `rlm` semantics.

func Empty

1func Empty(t uassert.TestingT, obj any, msgs ...string)
source

Empty requires that the specified object is empty (zero value, empty string/slice/map, or nil).

func Equal

1func Equal(t uassert.TestingT, expected, actual any, msgs ...string)
source

Equal requires that two objects are equal.

func Error

1func Error(t uassert.TestingT, err error, msgs ...string)
source

Error requires that a function returned an error (i.e. not `nil`).

func ErrorContains

1func ErrorContains(t uassert.TestingT, err error, contains string, msgs ...string)
source

ErrorContains requires that a function returned an error (i.e. not `nil`) and that the error contains the specified substring.

func ErrorIs

1func ErrorIs(t uassert.TestingT, err, target error, msgs ...string)
source

ErrorIs requires that the given error matches the target error.

func False

1func False(t uassert.TestingT, value bool, msgs ...string)
source

False requires that the specified value is false.

func Nil

1func Nil(t uassert.TestingT, value any, msgs ...string)
source

Nil requires that the value is nil.

func NoError

1func NoError(t uassert.TestingT, err error, msgs ...string)
source

NoError requires that a function returned no error (i.e. `nil`).

func NotAborts

1func NotAborts(t uassert.TestingT, rlm realm, f any, msgs ...string)
source

NotAborts requires that the code inside the specified func does NOT abort when crossing an execution boundary (e.g., VM call). Use NotPanics for requiring the absence of local panics within the same realm. Note: This relies on Gno's `revive` mechanism. See uassert.AbortsWithMessage for `rlm` semantics.

func NotEmpty

1func NotEmpty(t uassert.TestingT, obj any, msgs ...string)
source

NotEmpty requires that the specified object is not empty.

func NotEqual

1func NotEqual(t uassert.TestingT, expected, actual any, msgs ...string)
source

NotEqual requires that two objects are not equal.

func NotNil

1func NotNil(t uassert.TestingT, value any, msgs ...string)
source

NotNil requires that the value is not nil.

func NotPanics

1func NotPanics(t uassert.TestingT, rlm realm, f any, msgs ...string)
source

NotPanics requires that the code inside the specified func does NOT panic locally within the same execution realm. Use NotAborts for requiring the absence of panics that cross execution boundaries (aborts). See uassert.AbortsWithMessage for `rlm` semantics.

func NotTypedNil

1func NotTypedNil(t uassert.TestingT, value any, msgs ...string)
source

NotTypedNil requires that the value is not a typed-nil (nil pointer) value.

func PanicsContains

1func PanicsContains(t uassert.TestingT, rlm realm, substr string, f any, msgs ...string)
source

PanicsContains requires that the code inside the specified func panics locally within the same execution realm and the panic message contains the specified substring. See uassert.AbortsWithMessage for `rlm` semantics.

func PanicsWithMessage

1func PanicsWithMessage(t uassert.TestingT, rlm realm, msg string, f any, msgs ...string)
source

PanicsWithMessage requires that the code inside the specified func panics locally within the same execution realm. Use AbortsWithMessage for requiring panics that cross execution boundaries (aborts). See uassert.AbortsWithMessage for `rlm` semantics.

func True

1func True(t uassert.TestingT, value bool, msgs ...string)
source

True requires that the specified value is true.

func TypedNil

1func TypedNil(t uassert.TestingT, value any, msgs ...string)
source

TypedNil requires that the value is a typed-nil (nil pointer) value.

Imports 1

Source Files 4