Documentation
¶
Overview ¶
Package testoplugin provides plugin primitives for using plugins in testo.
Implementing a plugin ¶
Plugins can implement Plugin interface to be registered as such.
Method "Plugin" will be called for each plugin before running a suite. Parent is nil for top-level tests. For sub-tests it referes to the plugin instance of the parent test.
It is encouraged to ensure a plugin implements Plugin interface with the following line:
var _ testoplugin.Plugin = (*PluginFoo)(nil)
Index ¶
- type FuncChdir
- type FuncCleanup
- type FuncContext
- type FuncDeadline
- type FuncError
- type FuncFail
- type FuncFailNow
- type FuncFailed
- type FuncFatal
- type FuncLog
- type FuncParallel
- type FuncSetenv
- type FuncSkip
- type FuncSkipNow
- type FuncSkipped
- type FuncTempDir
- type Hook
- type Hooks
- type Option
- type Override
- type Overrides
- type Plan
- type PlannedTest
- type Plugin
- type Priority
- type Spec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FuncChdir ¶ added in v1.1.0
type FuncChdir func(dir string)
FuncChdir describes testing.T.Chdir method.
type FuncCleanup ¶ added in v1.1.0
type FuncCleanup func(f func())
FuncCleanup describes testing.T.Cleanup method.
type FuncContext ¶
FuncContext describes testing.T.Context method.
type FuncDeadline ¶
FuncDeadline describes testing.T.Deadline method.
type FuncSetenv ¶
type FuncSetenv func(key, value string)
FuncSetenv describes testing.T.Setenv 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 Priority
// Func to be run for this hook.
Func func()
}
Hook is the plugin hook.
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.
//
// WARN: this hook is defered to run at the end of the test.
// If that test has sub-tests marked as parallel,
// this hook will run BEFORE those sub-tests are finished.
//
// Unless you need to run sub-tests during this hook,
// it is recommended to use t.Cleanup during BeforeEachSub.
AfterEachSub Hook
// AfterEach is called after each test.
//
// NOTE: this hook is defered to run at the end of the test.
// If that test has sub-tests marked as parallel,
// this hook will run BEFORE those sub-tests are finished.
//
// Unless you need to run sub-tests during this hook,
// it is recommended to use t.Cleanup during BeforeEach.
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 to all subtests.
Propagate bool
}
Option is used to configure plugin upon creation.
All user-supplied options are passed to the Plugin 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.Value.(MyPluginOption)
func (Option) Propagated ¶
Propagated returns a shallow clone of this option with "Propagate" field set to true.
type Override ¶
type Override[F any] func(f F) F
Override for the function.
Nil value is valid and represents absence of override.
Use Override.Call to safely call an override.
type Overrides ¶
type Overrides struct {
// Priority defines global priority for these overrides.
// Overrides with lower priority values are called first.
Priority Priority
Log Override[FuncLog]
Parallel Override[FuncParallel]
TempDir Override[FuncTempDir]
Deadline Override[FuncDeadline]
Context Override[FuncContext]
Cleanup Override[FuncCleanup]
// Setenv calls Cleanup to restore an environment variable.
// On error, it calls Fatal.
Setenv Override[FuncSetenv]
// Chdir calls Cleanup to restore a current directory.
// On error, it calls Fatal.
Chdir Override[FuncChdir]
// Error calls Log followed by Fail.
Error Override[FuncError]
// Skip calls Log followed by SkipNow.
Skip Override[FuncSkip]
SkipNow Override[FuncSkipNow]
Skipped Override[FuncSkipped]
Fail Override[FuncFail]
FailNow Override[FuncFailNow]
Failed Override[FuncFailed]
// Fatal calls Log followed by FailNow.
Fatal Override[FuncFatal]
}
Overrides defines all builtin methods of T a plugin can override.
Overrides work using middleware pattern - multiple overrides are stacked on top of each other, passing by a "next" function.
There exists a certain hierarchy what method calls what underneath. For example, overriding Log will affect Error, Skip, Fatal and their printf equivalents.
type Plan ¶
type Plan struct {
// Priority sets plan priority.
// Plans with lower priority value are executed first.
Priority Priority
// Prepare may filter or re-order planned tests in-place.
// Nil values are ignored.
//
// This function will be called once before running any top-level tests.
// It will not receive subtests.
Prepare func(suite testoreflect.SuiteInfo, tests *[]PlannedTest)
}
Plan for running the tests.
type PlannedTest ¶
type PlannedTest interface {
pragma.DoNotImplement
// Info about this test.
Info() testoreflect.TestInfo
// Annotations of this test.
Annotations() []Option
}
PlannedTest is a test to be scheduled for execution.
type Plugin ¶
Plugin is an interface that plugins implement to provide Plan, Hooks and Overrides to the tests.