diff --git a/CHANGELOG.md b/CHANGELOG.md index 0435cb4..45b07d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ 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 + +- Support for setting plugin priority (order) for `Plan` and `Overrides` components. + +### Fixed + +- Add missing call to `t.Helper` in runner. + ## [1.3.2] - 2026-05-30 ### Fixed diff --git a/plugin.go b/plugin.go index 2f666f7..ba02540 100644 --- a/plugin.go +++ b/plugin.go @@ -33,6 +33,10 @@ func mergeSpecs(tb testing.TB, plugins ...testoplugin.Spec) testoplugin.Spec { func mergePlans(tb testing.TB, plans ...testoplugin.Plan) testoplugin.Plan { tb.Helper() + slices.SortStableFunc(plans, func(a, b testoplugin.Plan) int { + return cmp.Compare(a.Priority, b.Priority) + }) + return testoplugin.Plan{ Prepare: func(suite testoreflect.SuiteInfo, tests *[]testoplugin.PlannedTest) { tb.Helper() @@ -113,6 +117,10 @@ func mergeHooks(tb testing.TB, hooks ...testoplugin.Hooks) testoplugin.Hooks { //nolint:funlen // splitting this into subfunctons would make it worse func mergeOverrides(overrides ...testoplugin.Overrides) testoplugin.Overrides { + slices.SortStableFunc(overrides, func(a, b testoplugin.Overrides) int { + return cmp.Compare(a.Priority, b.Priority) + }) + return testoplugin.Overrides{ Log: mergeOverride( overrides, diff --git a/runner.go b/runner.go index eb598bf..eff605f 100644 --- a/runner.go +++ b/runner.go @@ -347,6 +347,8 @@ func (r *runner[Suite, T]) runSuiteTests(t T, s Suite, tests suiteTests[Suite, T for _, test := range allTests { testingT.Run(test.Name, func(testingT *testing.T) { + testingT.Helper() + innerT := construct( testingT, &t, diff --git a/testoplugin/overrides.go b/testoplugin/overrides.go index 04b365d..42ba39f 100644 --- a/testoplugin/overrides.go +++ b/testoplugin/overrides.go @@ -13,6 +13,10 @@ import ( // There exists a certain hierarchy what method calls what underneath. // For example, overriding Log will affect Error, Skip, Fatal and their printf equivalents. 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] diff --git a/testoplugin/plan.go b/testoplugin/plan.go index b994964..6107588 100644 --- a/testoplugin/plan.go +++ b/testoplugin/plan.go @@ -7,6 +7,10 @@ import ( // Plan for running the tests. 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. // diff --git a/testoplugin/plugin.go b/testoplugin/plugin.go index e66fc9c..e391ad8 100644 --- a/testoplugin/plugin.go +++ b/testoplugin/plugin.go @@ -15,10 +15,12 @@ package testoplugin import "math" // Priority defines execution order (priority). -// It defines when a plugin part should be invoked when other parts are available. +// It defines when a plugin component should be +// invoked when other parts are available. // -// "Plugin part" means plan, hook, override, etc. -// Right now, only [Hook]s are supported. +// "Plugin component" means plan, hook, override, etc. +// +// See [TryFirst] and [TryLast] for predefined priority values. type Priority int const (