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.

uassert - test assertions

Assertion helpers for writing Gno tests, in both _test.gno and _filetest.gno files. Adapted, lighter port of stretchr/testify/assert. Each helper takes a TestingT, reports the failure via t.Errorf, and lets the test keep running.

Usage

 1import (
 2    "testing"
 3
 4    "gno.land/p/nt/uassert/v0"
 5)
 6
 7func TestAdd(cur realm, t *testing.T) {
 8    got, err := Add(2, 3)
 9    uassert.NoError(t, err)
10    uassert.Equal(t, 5, got)
11    uassert.True(t, got > 0, "result must be positive")
12
13    uassert.PanicsWithMessage(t, cur, "div by zero", func() {
14        Div(1, 0)
15    })
16}

Every helper returns a bool (true on success) so they can be chained or used in conditionals.

API

1type TestingT interface {
2    Helper()
3    Skip(args ...any)
4    Fatalf(fmt string, args ...any)
5    Errorf(fmt string, args ...any)
6    Logf(fmt string, args ...any)
7    Fail()
8    FailNow()
9}

Equality and emptiness (supports string, address, bool, all int/uint widths, float32/64):

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

Truthiness and nil:

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

Errors:

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

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

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

Notes

  • A panic is a same-realm runtime failure caught with recover. An abort is a panic that crosses a realm boundary, caught with gno's revive. Use the right variant: PanicsX for same-realm, AbortsX for cross-realm. NotPanics covers both.
  • uassert reports the failure but lets the test continue. Use gno.land/p/nt/urequire/v0 when subsequent assertions wouldn't be meaningful after a 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.

uassert is an adapted lighter version of https://github.com/stretchr/testify/assert.

Functions 20

func AbortsContains

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

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

func AbortsWithMessage

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

AbortsWithMessage asserts that the code inside the specified func aborts (panics when crossing another realm). Use PanicsWithMessage for asserting local panics within the same realm.

`rlm` is threaded into the callback via cross(rlm) when f is func(realm). It is ignored for func() callbacks. /p/ production code cannot declare crossing functions, so rlm is taken as the second (non-first) parameter — callers pass `cur` directly.

NOTE: This relies on gno's `revive` mechanism to catch aborts.

func Empty

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

func Equal

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

Equal asserts that two objects are equal.

func Error

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

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

func ErrorContains

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

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

func ErrorIs

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

ErrorIs asserts the given error matches the target error using errors.Is, which traverses the error chain looking for a match.

func False

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

False asserts that the specified value is false.

func Nil

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

Nil asserts that the value is nil.

func NoError

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

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

func NotAborts

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

NotAborts asserts that the code inside the specified func does NOT abort when crossing an execution boundary. Note: Consider using NotPanics which checks for both panics and aborts. See AbortsWithMessage for `rlm` semantics.

func NotEmpty

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

func NotEqual

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

NotEqual asserts that two objects are not equal.

func NotNil

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

NotNil asserts that the value is not nil.

func NotPanics

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

NotPanics asserts that the code inside the specified func does NOT panic (within the same realm) or abort (due to a cross-realm panic). See AbortsWithMessage for `rlm` semantics.

func NotTypedNil

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

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

func PanicsContains

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

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

func PanicsWithMessage

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

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

func True

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

True asserts that the specified value is true.

func TypedNil

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

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

Types 1

type TestingT

interface
1type TestingT interface {
2	Helper()
3	Skip(args ...any)
4	Fatalf(fmt string, args ...any)
5	Errorf(fmt string, args ...any)
6	Logf(fmt string, args ...any)
7	Fail()
8	FailNow()
9}
source

Imports 5

Source Files 6