PathrockNetwork Gno Explorer
HomeBlocksTransactionsTokensRealmsPackagesValidatorsAnalytics

PathrockNetwork Gno Explorer — an independent explorer for Gno.land Mainnet (gnoland-1), operated by PathrockNetwork. Not an official Gno.land service.

gnowebarchive RPC

gno.land/p/g17khqpukees4237dtn3astzapmp462vjhsz6st4/expect

Package
Open in gnoweb ↗

Overview

Kind
Pure package
Name
expect
Namespace
g17khqpukees4237dtn3astzapmp462vjhsz6st4
Files
13 (README)(gnomod.toml)
Exported functions
n/a — not supported for pure packages by the node (vm/qfuncs)
Module
gno.land/p/g17khqpukees4237dtn3astzapmp462vjhsz6st4/expect
gno
0.9

Files (13)

  • README.mdmarkdown
  • gnomod.tomltoml
  • boolean.gnogno
  • context.gnogno
  • doc.gnogno
  • error.gnogno
  • float.gnogno
  • func.gnogno
  • int.gnogno
  • message.gnogno
  • string.gnogno
  • uint.gnogno
  • value.gnogno
  • context.gnogno
    1package expect23import (4	"strings"56	"gno.land/p/nt/ufmt/v0"7)89const defaultAssertFailMsg = "assert expectation failed"1011// NewContext creates a new testing context.12func NewContext(t TestingT) Context {13	return Context{t: t}14}1516// Context preserves the current testing context.17type Context struct {18	t       TestingT19	negated bool20	prefix  string21}2223// T returns context's testing T instance.24func (c Context) T() TestingT {25	if c.t == nil {26		panic("expect: context is not initialized")27	}28	return c.t29}3031// Prefix returns context's error prefix.32func (c Context) Prefix() string {33	return c.prefix34}3536// IsNegated checks if current context negates current assert expectations.37func (c Context) IsNegated() bool {38	return c.negated39}4041// CheckExpectation checks an assert expectation and calls a callback on fail.42// It returns true when the asserted expectation fails.43// Callback is called when a negated assertion succeeds or when non negated assertion fails.44func (c Context) CheckExpectation(success bool, cb func(Context) string) bool {45	failed := (c.negated && success) || (!c.negated && !success)46	if failed {47		msg := cb(c)48		if strings.TrimSpace(msg) == "" {49			msg = defaultAssertFailMsg50		}5152		c.Fail(msg)53	}54	return failed55}5657// Fail makes the current test fail with a custom message.58func (c Context) Fail(msg string, args ...any) {59	if c.prefix != "" {60		msg = c.prefix + " - " + msg61	}6263	c.t.Fatalf(msg, args...)64}6566// TestingT defines a minimal interface for `testing.T` instances.67type TestingT interface {68	Helper()69	Fatal(args ...any)70	Fatalf(format string, args ...any)71}7273// MockTestingT creates a new testing mock that writes testing output to a string builder.74func MockTestingT(output *strings.Builder) TestingT {75	return &testingT{output}76}7778type testingT struct{ buf *strings.Builder }7980func (testingT) Helper()                          {}81func (t testingT) Fatal(args ...any)              { t.buf.WriteString(ufmt.Sprintln(args...)) }82func (t testingT) Fatalf(fmt string, args ...any) { t.buf.WriteString(ufmt.Sprintf(fmt+"\n", args...)) }83

    Functions

    not supported for pure packages by the node (vm/qfuncs)

    Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.