diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bebc8e..03e18fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Added + +- `testo.Plugins` function to get plugin instances of a given `T`. + ## [1.8.0] - 2026-08-30 ### Added diff --git a/t.go b/t.go index 2c5cfe4..c45a9e8 100644 --- a/t.go +++ b/t.go @@ -620,18 +620,60 @@ func (t *T) logPlugins() { func Reflect(t CommonT) testoreflect.Reflection { t.Helper() - internal := t.unwrap() + u := t.unwrap() - info := internal.reflection.Load() + info := u.reflection.Load() - info.FailureSource = internal.failureSource.Load() - info.FailureKind = internal.failureKind.Load() - info.HasFatalSubtest = internal.hasFatalSubtest.Load() - info.TestingT = internal.testingT + info.FailureSource = u.failureSource.Load() + info.FailureKind = u.failureKind.Load() + info.HasFatalSubtest = u.hasFatalSubtest.Load() + info.TestingT = u.testingT return info } +// Plugins returns information about installed plugins +// in the given t instance. +// +// Returned slice follows plugins declaration order. +// +// For example: +// +// type T struct{ +// *testo.T +// *PluginBar +// *PluginFoo +// *PluginAllure +// } +// +// func (*Suite) Test(t T) { +// testo.Plugins(t) +// } +// +// Would return: +// +// []testoplugin.Plugin{*PluginBar(...), *PluginFoo(...), *PluginAllure(...)} +// +// NOTE: this function returns pointers to an actual plugin instances, so calling +// their methods is equivalent to calling T's methods. +func Plugins(t CommonT) []testoplugin.Plugin { + t.Helper() + + u := t.unwrap() + + plugins := make([]testoplugin.Plugin, 0, len(u.plugins)) + + for _, typ := range u.pluginOrder { + if typ == reflect.TypeFor[*T]() { + continue + } + + plugins = append(plugins, u.plugins[typ]) + } + + return plugins +} + type atomicInt[T ~int | ~int8 | ~int32 | ~int64] atomic.Int64 func (a *atomicInt[T]) Load() T {