plugin

package
v0.0.0-...-ab5b5df Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package plugin provides plugin primitives for using plugins in testo.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FuncDeadline

type FuncDeadline func() (deadline time.Time, ok bool)

FuncDeadline describes testing.T.Deadline method.

type FuncError

type FuncError func(args ...any)

FuncError describes testing.T.Error method.

type FuncErrorf

type FuncErrorf func(format string, args ...any)

FuncErrorf describes testing.T.Errorf method.

type FuncFail

type FuncFail func()

FuncFail describes testing.T.Fail method.

type FuncFailNow

type FuncFailNow func()

FuncFailNow describes testing.T.FailNow method.

type FuncFailed

type FuncFailed func() bool

FuncFailed describes testing.T.Failed method.

type FuncFatal

type FuncFatal func(args ...any)

FuncFatal describes testing.T.Fatal method.

type FuncFatalf

type FuncFatalf func(format string, args ...any)

FuncFatalf describes testing.T.Fatalf method.

type FuncLog

type FuncLog func(args ...any)

FuncLog describes testing.T.Log method.

type FuncLogf

type FuncLogf func(format string, args ...any)

FuncLogf describes testing.T.Logf method.

type FuncName

type FuncName func() string

FuncName describes testing.T.Name method.

type FuncParallel

type FuncParallel func()

FuncParallel describes testing.T.Parallel method.

type FuncSetenv

type FuncSetenv func(key, value string)

FuncSetenv describes testing.T.Setenv method.

type FuncSkip

type FuncSkip func(args ...any)

FuncSkip describes testing.T.Skip method.

type FuncSkipNow

type FuncSkipNow func()

FuncSkipNow describes testing.T.SkipNow method.

type FuncSkipf

type FuncSkipf func(format string, args ...any)

FuncSkipf describes testing.T.Skipf method.

type FuncSkipped

type FuncSkipped func() bool

FuncSkipped describes testing.T.Skipped method.

type FuncTempDir

type FuncTempDir func() string

FuncTempDir describes testing.T.TempDir method.

type Hook

type Hook struct {
	// Priority defines execution order.
	// Lower values indicate that this hook should be run earlier than others and vice versa.
	// Zero value won't affect the order - it uses stable sort internally.
	//
	// See [TryFirst] and [TryLast] for predefined priority constants.
	Priority HookPriority

	// Func to be run for this hook.
	Func func()
}

Hook is the plugin hook.

func (Hook) Run

func (h Hook) Run()

Run this hook. Calling this function with nil [Hook.Func] is safe and no op.

type HookPriority

type HookPriority int

HookPriority is the Hook priority. It defines when a hook should be invoked when other hooks are available.

const (
	// TryFirst indicates that this hook should be run as early as possible.
	TryFirst HookPriority = -1

	// TryLast indicates that this hook should be run as late as possible.
	TryLast HookPriority = 1
)

type Hooks

type Hooks struct {
	// BeforeAll is called before all tests once.
	BeforeAll Hook

	// BeforeEach is called before each test.
	BeforeEach Hook

	// BeforeEachSub is called before each subtest.
	BeforeEachSub Hook

	// AfterEachSub is called after each subtest.
	AfterEachSub Hook

	// AfterEach is called after each test.
	AfterEach Hook

	// AfterAll is called after all tests once.
	AfterAll Hook
}

Hooks defines all hooks a plugin can define.

type Option

type Option struct {
	// Value of this option.
	Value any

	// Propagate states whether this option
	// should be passed automatically between all subtests.
	Propagate bool
}

Option is used to configure plugin upon creation.

All user-supplied options are passed to the Init method for each plugin. It is a plugin responsibility to check if the given option corresponds to it. One way to check it is with type assertion:

var opt Option
o, ok := opt.(MyOption)

type Override

type Override[F any] func(f F) F

Override for the function.

Nil value is valid and represents absence of override.

func (Override[F]) Call

func (o Override[F]) Call(f F) F

Call returns an overridden f. If override is nil f is returned as is.

type Overrides

type Overrides struct {
	// Log overrides [testing.T.Log] function.
	//
	// Note that overriding this function won't override internal log used for Logf
	// or other functions such as Error, Skip, Fatal, etc.
	Log Override[FuncLog]

	// Logf overrides [testing.T.Logf] function.
	//
	// Note that overriding this function won't override internal log used for Logf
	// or other functions such as Errorf, Skipf, Fatalf, etc.
	Logf Override[FuncLogf]

	Name     Override[FuncName]
	Parallel Override[FuncParallel]
	Setenv   Override[FuncSetenv]
	TempDir  Override[FuncTempDir]
	Deadline Override[FuncDeadline]
	Errorf   Override[FuncErrorf]
	Error    Override[FuncError]
	Skip     Override[FuncSkip]
	SkipNow  Override[FuncSkipNow]
	Skipf    Override[FuncSkipf]
	Skipped  Override[FuncSkipped]
	Fail     Override[FuncFail]
	FailNow  Override[FuncFailNow]
	Failed   Override[FuncFailed]
	Fatal    Override[FuncFatal]
	Fatalf   Override[FuncFatalf]
}

Overrides defines all builtin methods of T a plugin can override.

type PanicInfo

type PanicInfo struct {
	// Value returned by recover().
	Value any

	// Trace is a stack trace for this panic.
	Trace string
}

PanicInfo holds information for recovered panic.

type ParametrizedTestInfo

type ParametrizedTestInfo struct {
	// RawBaseName of the test.
	//
	// When defined like so:
	//
	//  func TestFoo(t T, params struct{ ... }) {}
	//
	// Testo will create a separate test for each case
	// and name it "TestFoo_case_N" where N is the 1-based case number.
	// Therefore, t.BaseName() would also equal to "TestFoo_case_N",
	// while this field would store "TestFoo".
	RawBaseName string

	// N is the 0-based case number of this test.
	N int

	// Params passed for the current test case.
	Params map[string]any
}

ParametrizedTestInfo is the information about parametrized test.

type Plan

type Plan struct {
	// Modify may filter or re-order planned tests in-place.
	// Nil values are ignored.
	//
	// It will not receive subtests.
	Modify func(tests *[]PlannedTest)
}

Plan for running the tests.

type PlannedTest

type PlannedTest interface {
	directive.DoNotImplement

	// Name of the test.
	Name() string

	// Info about this test.
	Info() TestInfo
}

PlannedTest is a test to be scheduled for execution.

type Plugin

type Plugin interface {
	Plugin() Spec
}

Plugin is an interface that plugins implement to provide Plan, Hooks and Overrides to the tests.

func Collect

func Collect(v any) []Plugin

Collect plugins from the v.

Plugins are stored as (possibly anonymous) fields and implement Plugin interface.

If v itself implements Plugin interface it will collect it first and then traverse through its fields recursively.

type RegularTestInfo

type RegularTestInfo struct {
	// RawBaseName is the raw "unformatted" base name of this test.
	//
	// For example:
	//
	//   Run(t, "my test name!?", func(...) { ... })
	//
	// t.BaseName() would equal to my_test_name,
	// while this field would equal to "my test name!?" (the same as passed).
	//
	// This only applies to subtests, for regular test
	// functions BaseName() and this field are equal.
	RawBaseName string

	// Level indicates how deep this t is.
	// That is, it shows the number of parents it has and zero if none.
	//
	// 	- Zero level is above test methods and exists in Before/After-All hooks.
	//  - First level is the test method level.
	//  - Second and more levels are subtests.
	Level int
}

RegularTestInfo is the information about regular (non-parametrized) test.

type Spec

type Spec struct {
	Plan      Plan
	Hooks     Hooks
	Overrides Overrides
}

Spec specification.

func MergeSpecs

func MergeSpecs(plugins ...Spec) Spec

MergeSpecs multiple plugin specs into one.

type TInfo

type TInfo struct {
	// Plugins used by this T.
	Plugins []Plugin

	// Test holds information about current test.
	Test TestInfo

	// Panic is panic information.
	// It is nil if the test did not panic.
	Panic *PanicInfo

	// FailureKind is test failure kind.
	FailureKind TestFailureKind
}

TInfo is extra information about T.

type TestFailureKind

type TestFailureKind int

TestFailureKind defines test failure kinds.

const (
	// TestFailureKindNone states that test did not fail.
	TestFailureKindNone TestFailureKind = iota

	// TestFailureKindSoft states that test failed but it was not fatal.
	// For example, t.Fail() was called.
	TestFailureKindSoft

	// TestFailureKindFatal states that test failed with fatal error.
	// For example, t.FailNow() or t.Fatal() were called.
	TestFailureKindFatal
)

type TestInfo

type TestInfo interface {
	// contains filtered or unexported methods
}

TestInfo is a enum which is either ParametrizedTestInfo or RegularTestInfo.

Jump to

Keyboard shortcuts

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