diff --git a/src/main/java/com/thoughtworks/gauge/execution/HookExecutionStage.java b/src/main/java/com/thoughtworks/gauge/execution/HookExecutionStage.java index e3599552..60c2aff8 100644 --- a/src/main/java/com/thoughtworks/gauge/execution/HookExecutionStage.java +++ b/src/main/java/com/thoughtworks/gauge/execution/HookExecutionStage.java @@ -28,6 +28,9 @@ public void setNextStage(ExecutionStage stage) { } public Spec.ProtoExecutionResult execute(Spec.ProtoExecutionResult result) { + if (result.getFailed() || result.getSkipScenario()) { + return executeNext(result); + } Spec.ProtoExecutionResult execResult = execute(); Spec.ProtoExecutionResult stageResult = mergeExecResults(result, execResult); return executeNext(stageResult); diff --git a/src/main/java/com/thoughtworks/gauge/execution/HooksExecutor.java b/src/main/java/com/thoughtworks/gauge/execution/HooksExecutor.java index fc24cbb3..b0506434 100644 --- a/src/main/java/com/thoughtworks/gauge/execution/HooksExecutor.java +++ b/src/main/java/com/thoughtworks/gauge/execution/HooksExecutor.java @@ -34,7 +34,7 @@ public Spec.ProtoExecutionResult execute() { for (Hook hook : hooks) { result = new TaggedHookExecutor(hook, info).execute(); totalHooksExecutionTime += result.getExecutionTime(); - if (result.getFailed()) { + if (result.getFailed() || result.getSkipScenario()) { return Spec.ProtoExecutionResult.newBuilder(result).setExecutionTime(totalHooksExecutionTime).build(); } } diff --git a/src/main/java/com/thoughtworks/gauge/execution/StepExecutionStage.java b/src/main/java/com/thoughtworks/gauge/execution/StepExecutionStage.java index 32b693f7..39f05164 100644 --- a/src/main/java/com/thoughtworks/gauge/execution/StepExecutionStage.java +++ b/src/main/java/com/thoughtworks/gauge/execution/StepExecutionStage.java @@ -35,7 +35,7 @@ public void setNextStage(ExecutionStage stage) { } public Spec.ProtoExecutionResult execute(Spec.ProtoExecutionResult previousStageResult) { - if (previousStageResult.getFailed()) { + if (previousStageResult.getFailed() || previousStageResult.getSkipScenario()) { return executeNext(previousStageResult); } Spec.ProtoExecutionResult stageResult = executeStep(); diff --git a/src/test/java/com/thoughtworks/gauge/execution/HookExecutionStageTest.java b/src/test/java/com/thoughtworks/gauge/execution/HookExecutionStageTest.java new file mode 100644 index 00000000..554e4ac8 --- /dev/null +++ b/src/test/java/com/thoughtworks/gauge/execution/HookExecutionStageTest.java @@ -0,0 +1,16 @@ +package com.thoughtworks.gauge.execution; + +import gauge.messages.Spec; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class HookExecutionStageTest { + @Test + public void shouldShortCircuitIfPreviousStageSkipped() { + HookExecutionStage stage = new HookExecutionStage(java.util.Collections.emptyList(), new com.thoughtworks.gauge.ClassInstanceManager()); + Spec.ProtoExecutionResult previous = Spec.ProtoExecutionResult.newBuilder().setSkipScenario(true).build(); + Spec.ProtoExecutionResult result = stage.execute(previous); + assertTrue(result.getSkipScenario()); + } +} \ No newline at end of file diff --git a/src/test/java/com/thoughtworks/gauge/execution/StepExecutionStageTest.java b/src/test/java/com/thoughtworks/gauge/execution/StepExecutionStageTest.java index 67199c6c..de2da117 100644 --- a/src/test/java/com/thoughtworks/gauge/execution/StepExecutionStageTest.java +++ b/src/test/java/com/thoughtworks/gauge/execution/StepExecutionStageTest.java @@ -251,4 +251,18 @@ public Object table(Object table) { public void skipScenarioStep() { throw new com.thoughtworks.gauge.SkipScenarioException("skipping this scenario due to unmet condition"); } + + @Test + public void shouldShortCircuitIfPreviousStageSkipped() { + Messages.ExecuteStepRequest executeStepRequest = Messages.ExecuteStepRequest.newBuilder() + .setParsedStepText("foo bar") + .setActualStepText("foo bar") + .build(); + StepExecutionStage executionStage = new StepExecutionStage( + executeStepRequest, new ClassInstanceManager(), new ParameterParsingChain(), mock(StepRegistry.class) + ); + Spec.ProtoExecutionResult previous = Spec.ProtoExecutionResult.newBuilder().setSkipScenario(true).build(); + Spec.ProtoExecutionResult result = executionStage.execute(previous); + assertTrue(result.getSkipScenario()); + } }