Documentation
¶
Overview ¶
Package plugin provides plugin primitives for using plugins in testo.
Index ¶
- type FuncDeadline
- type FuncError
- type FuncErrorf
- type FuncFail
- type FuncFailNow
- type FuncFailed
- type FuncFatal
- type FuncFatalf
- type FuncLog
- type FuncLogf
- type FuncName
- type FuncParallel
- type FuncSetenv
- type FuncSkip
- type FuncSkipNow
- type FuncSkipf
- type FuncSkipped
- type FuncTempDir
- type Hook
- type HookPriority
- type Hooks
- type Option
- type Override
- type Overrides
- type PanicInfo
- type ParametrizedTestInfo
- type Plan
- type PlannedTest
- type Plugin
- type RegularTestInfo
- type Spec
- type TInfo
- type TestFailureKind
- type TestInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FuncDeadline ¶
FuncDeadline describes testing.T.Deadline method.
type FuncErrorf ¶
FuncErrorf describes testing.T.Errorf method.
type FuncFatalf ¶
FuncFatalf describes testing.T.Fatalf method.
type FuncLogf ¶
FuncLogf describes testing.T.Logf method.
type FuncSetenv ¶
type FuncSetenv func(key, value string)
FuncSetenv describes testing.T.Setenv method.
type FuncSkipf ¶
FuncSkipf describes testing.T.Skipf 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.
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.
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.
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 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.