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
- Variables
- type FailError
- type SkipError
- type T
- func (t *T) AddSub(child *T)
- func (t *T) CallName(name string, c gad.Call) (gad.Object, error)
- func (t *T) Equal(right gad.Object) bool
- func (t *T) Failure() bool
- func (t *T) Failures() []string
- func (t *T) IndexGet(_ *gad.VM, index gad.Object) (gad.Object, error)
- func (t *T) IsFalsy() bool
- func (t *T) Logs() []string
- func (t *T) Name() string
- func (t *T) SelfFailed() bool
- func (t *T) SetBenchN(n int)
- func (t *T) Skipped() (bool, string)
- func (t *T) Subs() []*T
- func (t *T) ToString() string
- func (t *T) Type() gad.ObjectType
Constants ¶
const ModuleName = "test"
ModuleName is the import/builtin name of the module.
Variables ¶
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.
var ModuleInit = gad.ModuleInitFunc(func(module *gad.Module, c gad.Call) (err error) { module.Data = Module return })
ModuleInit registers the module data.
var TT = gad.NewBuiltinObjType("T")
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.
type SkipError ¶
type SkipError struct{ Msg string }
SkipError is returned by t.skip to stop and mark the test skipped.
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 (*T) Failure ¶
Failure reports whether this test or any of its subtests failed (like Go's testing.T.Failed).
func (*T) SelfFailed ¶
SelfFailed reports whether this test recorded a failure of its own (not counting subtests).
func (*T) Type ¶
func (t *T) Type() gad.ObjectType