/p/nt/uassert/v0
Directory · 8 Files
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'srevive. Use the right variant:PanicsXfor same-realm,AbortsXfor cross-realm.NotPanicscovers both. uassertreports the failure but lets the test continue. Usegno.land/p/nt/urequire/v0when subsequent assertions wouldn't be meaningful after a failure.