diff --git a/docs/release_notes.adoc b/docs/release_notes.adoc index 45652ce7d0..c2708d81ff 100644 --- a/docs/release_notes.adoc +++ b/docs/release_notes.adoc @@ -5,6 +5,8 @@ include::include.adoc[] == 2.4 (tbd) +* Support for setting execution order (a.k.a. run order) in `SpecInfo`, can be used by extensions + == 2.4-M1 (2022-11-30) * Fix issues with Spring 6/Spring Boot 3 spockPull:1541[] diff --git a/spock-core/src/main/java/org/spockframework/runtime/SpockEngineDiscoveryPostProcessor.java b/spock-core/src/main/java/org/spockframework/runtime/SpockEngineDiscoveryPostProcessor.java index 6c900e1704..d01d4e29cc 100644 --- a/spock-core/src/main/java/org/spockframework/runtime/SpockEngineDiscoveryPostProcessor.java +++ b/spock-core/src/main/java/org/spockframework/runtime/SpockEngineDiscoveryPostProcessor.java @@ -5,6 +5,8 @@ import org.junit.platform.engine.*; +import static java.util.Comparator.comparingInt; + class SpockEngineDiscoveryPostProcessor { private static final Object[] EMPTY_ARGS = new Object[0]; @@ -14,6 +16,7 @@ SpockEngineDescriptor postProcessEngineDescriptor(UniqueId uniqueId, RunContext SpockEngineDescriptor processedEngineDescriptor = new SpockEngineDescriptor(uniqueId, runContext); engineDescriptor.getChildren().stream() .map(child -> processSpecNode(child, runContext)) + .sorted(comparingInt(child -> child instanceof SpecNode ? ((SpecNode) child).getNodeInfo().getExecutionOrder() : 0)) .forEach(processedEngineDescriptor::addChild); return processedEngineDescriptor; } diff --git a/spock-core/src/main/java/org/spockframework/runtime/model/SpecInfo.java b/spock-core/src/main/java/org/spockframework/runtime/model/SpecInfo.java index 287528214b..22da3adee0 100644 --- a/spock-core/src/main/java/org/spockframework/runtime/model/SpecInfo.java +++ b/spock-core/src/main/java/org/spockframework/runtime/model/SpecInfo.java @@ -48,6 +48,8 @@ public class SpecInfo extends SpecElementInfo> implements IMe private ExecutionMode executionMode = null; private ExecutionMode childExecutionMode = null; + private int executionOrder; + private String pkg; private String filename; private String narrative; @@ -66,6 +68,14 @@ public class SpecInfo extends SpecElementInfo> implements IMe private final List features = new ArrayList<>(); + public int getExecutionOrder() { + return executionOrder; + } + + public void setExecutionOrder(int executionOrder) { + this.executionOrder = executionOrder; + } + public String getPackage() { return pkg; }