test

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package test provides the `test` builtin module and the `T` context passed to test/benchmark functions run by `gad test`. Its assertions mirror Go's testing + testify/require: a failed assertion records the failure and aborts the current test (require semantics).

Index

Constants

View Source
const ModuleName = "test"

ModuleName is the import/builtin name of the module.

Variables

View Source
var Module = gad.Dict{

	"T": TT,

	"equal":    reqFn("equal"),
	"notEqual": reqFn("notEqual"),
	"true":     reqFn("true"),
	"false":    reqFn("false"),
	"nil":      reqFn("nil"),
	"notNil":   reqFn("notNil"),
	"contains": reqFn("contains"),
	"error":    reqFn("error"),
	"noError":  reqFn("noError"),
	"fail":     reqFn("fail"),
	"fatal":    reqFn("fatal"),
}

Module is the `test` builtin namespace.

View Source
var ModuleInit = gad.ModuleInitFunc(func(module *gad.Module, c gad.Call) (err error) {
	module.Data = Module
	return
})

ModuleInit registers the module data.

TT is the object type of the test context `T`.

Functions

This section is empty.

Types

type FailError

type FailError struct{ Msg string }

FailError is returned by an assertion (or t.fatal) to abort the running test; the runner catches it and records the failure via the test context state.

func (*FailError) Error

func (e *FailError) Error() string

type SkipError

type SkipError struct{ Msg string }

SkipError is returned by t.skip to stop and mark the test skipped.

func (*SkipError) Error

func (e *SkipError) Error() string

type T

type T struct {
	// contains filtered or unexported fields
}

T is the per-test context. Assertion methods record a failure and, being require-style, abort by returning a FailError. Subtests started with `t.run` (or nested `test NAME { … }` statements) are recorded in subs.

func NewT

func NewT(name string) *T

NewT returns a fresh test context named name.

func (*T) AddSub

func (t *T) AddSub(child *T)

AddSub records child as a subtest of t.

func (*T) CallName

func (t *T) CallName(name string, c gad.Call) (gad.Object, error)

CallName dispatches t's methods (assertions and controls).

func (*T) Equal

func (t *T) Equal(right gad.Object) bool

func (*T) Failure

func (t *T) Failure() bool

Failure reports whether this test or any of its subtests failed (like Go's testing.T.Failed).

func (*T) Failures

func (t *T) Failures() []string

Failures are the failure messages recorded by this test itself.

func (*T) IndexGet

func (t *T) IndexGet(_ *gad.VM, index gad.Object) (gad.Object, error)

IndexGet exposes read-only fields: .name, .failed, .n (benchmark count).

func (*T) IsFalsy

func (t *T) IsFalsy() bool

func (*T) Logs

func (t *T) Logs() []string

Logs are the messages written with t.log.

func (*T) Name

func (t *T) Name() string

Name is the test's name.

func (*T) SelfFailed

func (t *T) SelfFailed() bool

SelfFailed reports whether this test recorded a failure of its own (not counting subtests).

func (*T) SetBenchN

func (t *T) SetBenchN(n int)

SetBenchN sets the benchmark iteration count returned by t.n.

func (*T) Skipped

func (t *T) Skipped() (bool, string)

Skipped reports whether the test was skipped, with its message.

func (*T) Subs

func (t *T) Subs() []*T

Subs are the subtests started with t.run, in run order.

func (*T) ToString

func (t *T) ToString() string

func (*T) Type

func (t *T) Type() gad.ObjectType

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL