Skip to content

Commit 850705b

Browse files
fix: short-circuit execution for skipScenario in StepExecutionStage and HookExecutionStage; add corresponding tests
1 parent f70bb07 commit 850705b

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

src/main/java/com/thoughtworks/gauge/execution/HookExecutionStage.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public void setNextStage(ExecutionStage stage) {
2828
}
2929

3030
public Spec.ProtoExecutionResult execute(Spec.ProtoExecutionResult result) {
31+
if (result.getFailed() || result.getSkipScenario()) {
32+
return executeNext(result);
33+
}
3134
Spec.ProtoExecutionResult execResult = execute();
3235
Spec.ProtoExecutionResult stageResult = mergeExecResults(result, execResult);
3336
return executeNext(stageResult);

src/main/java/com/thoughtworks/gauge/execution/StepExecutionStage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void setNextStage(ExecutionStage stage) {
3535
}
3636

3737
public Spec.ProtoExecutionResult execute(Spec.ProtoExecutionResult previousStageResult) {
38-
if (previousStageResult.getFailed()) {
38+
if (previousStageResult.getFailed() || previousStageResult.getSkipScenario()) {
3939
return executeNext(previousStageResult);
4040
}
4141
Spec.ProtoExecutionResult stageResult = executeStep();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.thoughtworks.gauge.execution;
2+
3+
import gauge.messages.Spec;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static org.junit.jupiter.api.Assertions.assertTrue;
7+
8+
public class HookExecutionStageTest {
9+
@Test
10+
public void shouldShortCircuitIfPreviousStageSkipped() {
11+
HookExecutionStage stage = new HookExecutionStage(java.util.Collections.emptyList(), new com.thoughtworks.gauge.ClassInstanceManager());
12+
Spec.ProtoExecutionResult previous = Spec.ProtoExecutionResult.newBuilder().setSkipScenario(true).build();
13+
Spec.ProtoExecutionResult result = stage.execute(previous);
14+
assertTrue(result.getSkipScenario());
15+
}
16+
}

src/test/java/com/thoughtworks/gauge/execution/StepExecutionStageTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,18 @@ public Object table(Object table) {
251251
public void skipScenarioStep() {
252252
throw new com.thoughtworks.gauge.SkipScenarioException("skipping this scenario due to unmet condition");
253253
}
254+
255+
@Test
256+
public void shouldShortCircuitIfPreviousStageSkipped() {
257+
Messages.ExecuteStepRequest executeStepRequest = Messages.ExecuteStepRequest.newBuilder()
258+
.setParsedStepText("foo bar")
259+
.setActualStepText("foo bar")
260+
.build();
261+
StepExecutionStage executionStage = new StepExecutionStage(
262+
executeStepRequest, new ClassInstanceManager(), new ParameterParsingChain(), mock(StepRegistry.class)
263+
);
264+
Spec.ProtoExecutionResult previous = Spec.ProtoExecutionResult.newBuilder().setSkipScenario(true).build();
265+
Spec.ProtoExecutionResult result = executionStage.execute(previous);
266+
assertTrue(result.getSkipScenario());
267+
}
254268
}

0 commit comments

Comments
 (0)