func AbortsContains
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.
v0 - Unaudited: This is an initial version that has not yet been formally audited. A fully audited version will be pu...
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 assertionsAssertion 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.
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.
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
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.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.
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.
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.
Equal asserts that two objects are equal.
Error asserts that a function returned an error (i.e. not `nil`).
ErrorContains asserts that a function returned an error (i.e. not `nil`) and that the error contains the specified substring.
ErrorIs asserts the given error matches the target error using errors.Is, which traverses the error chain looking for a match.
False asserts that the specified value is false.
Nil asserts that the value is nil.
NoError asserts that a function returned no error (i.e. `nil`).
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.
NotEqual asserts that two objects are not equal.
NotNil asserts that the value is not nil.
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.
NotTypedNil asserts that the value is not a typed-nil (nil pointer) value.
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.
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.
True asserts that the specified value is true.
TypedNil asserts that the value is a typed-nil (nil pointer) value.