Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2102-fix-dry-run' into main
Given a scenario with several steps: ```feature Scenario: Given a passed step And a skipped step And an pending step And an undefined step And an ambiguous step ``` When executing this the outcome of the result is: ``` a passed step -> PASSED a skipped step -> SKIPPED an pending step -> PENDING an undefined step -> SKIPPED an ambiguous step -> AMBIGUOUS ``` This is wrong, because after the first non-passed result all other steps should be skipped. So: ``` a passed step -> PASSED a skipped step -> SKIPPED an pending step -> SKIPPED an undefined step -> SKIPPED an ambiguous step -> SKIPPED ``` When using executing this scenario with `--dry-run` the result is: ``` a passed step -> PASSED a skipped step -> PASSED an pending step -> PASSED an undefined step -> UNDEFINED an ambiguous step -> AMBIGUOUS ``` And surprisingly enough this is also wrong. While the skipped and pending states can only be detected by executing an implemented step, the undefined step should be marked as undefined and the ambiguous step that follows it should be skipped. ``` a passed step -> PASSED a skipped step -> PASSED an pending step -> PASSED an undefined step -> UNDEFINED an ambiguous step -> SKIPPED ``` The cause for this confusion lies in the fact that `--dry-run` was implemented using the skip mechanism rather then its own execution mode that is distinct from both a regular run and skip mode. By implementing these as individual execution modes we can avoid this confusion. Implementing this however revealed that our formatters were often being tested with completely undefined scenarios. This does not provide a representative test and allowed #2102 to come into existence. Fixing this was rather complicated, the formatters were being tested with an overly complicated mock implementation. Replacing this mock implementation with stubs made the tests more readable and removed a significant chunk of complexity. Fixes: #2102
- Loading branch information
Showing
48 changed files
with
2,142 additions
and
2,120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
core/src/main/java/io/cucumber/core/runner/ExecutionMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.cucumber.core.runner; | ||
|
||
import io.cucumber.plugin.event.Status; | ||
|
||
enum ExecutionMode { | ||
|
||
RUN { | ||
@Override | ||
Status execute(StepDefinitionMatch stepDefinitionMatch, TestCaseState state) throws Throwable { | ||
stepDefinitionMatch.runStep(state); | ||
return Status.PASSED; | ||
} | ||
|
||
}, | ||
DRY_RUN { | ||
@Override | ||
Status execute(StepDefinitionMatch stepDefinitionMatch, TestCaseState state) throws Throwable { | ||
stepDefinitionMatch.dryRunStep(state); | ||
return Status.PASSED; | ||
} | ||
}, | ||
SKIP { | ||
@Override | ||
Status execute(StepDefinitionMatch stepDefinitionMatch, TestCaseState state) { | ||
return Status.SKIPPED; | ||
} | ||
}; | ||
|
||
abstract Status execute(StepDefinitionMatch stepDefinitionMatch, TestCaseState state) throws Throwable; | ||
|
||
ExecutionMode next(ExecutionMode current) { | ||
return current == SKIP ? current : this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
core/src/test/java/io/cucumber/core/backend/StubHookDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package io.cucumber.core.backend; | ||
|
||
import java.util.function.Consumer; | ||
|
||
public class StubHookDefinition implements HookDefinition { | ||
|
||
private static final String STUBBED_LOCATION_WITH_DETAILS = "{stubbed location with details}"; | ||
private final String location; | ||
private final RuntimeException exception; | ||
private final Consumer<TestCaseState> action; | ||
|
||
public StubHookDefinition(String location, RuntimeException exception, Consumer<TestCaseState> action) { | ||
this.location = location; | ||
this.exception = exception; | ||
this.action = action; | ||
} | ||
|
||
public StubHookDefinition(String location, Consumer<TestCaseState> action) { | ||
this(location, null, action); | ||
} | ||
|
||
public StubHookDefinition() { | ||
this(STUBBED_LOCATION_WITH_DETAILS, null, null); | ||
} | ||
|
||
public StubHookDefinition(Consumer<TestCaseState> action) { | ||
this(STUBBED_LOCATION_WITH_DETAILS, null, action); | ||
} | ||
|
||
public StubHookDefinition(RuntimeException exception) { | ||
this(STUBBED_LOCATION_WITH_DETAILS, exception, null); | ||
} | ||
|
||
public StubHookDefinition(String location) { | ||
this(location, null, null); | ||
} | ||
|
||
@Override | ||
public void execute(TestCaseState state) { | ||
if (action != null) { | ||
action.accept(state); | ||
} | ||
if (exception != null) { | ||
throw exception; | ||
} | ||
} | ||
|
||
@Override | ||
public String getTagExpression() { | ||
return ""; | ||
} | ||
|
||
@Override | ||
public int getOrder() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public boolean isDefinedAt(StackTraceElement stackTraceElement) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public String getLocation() { | ||
return location; | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
core/src/test/java/io/cucumber/core/backend/StubPendingException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.cucumber.core.backend; | ||
|
||
import io.cucumber.core.backend.Pending; | ||
|
||
@Pending | ||
public final class StubPendingException extends RuntimeException { | ||
|
||
public StubPendingException() { | ||
this("TODO: implement me"); | ||
} | ||
|
||
public StubPendingException(String message) { | ||
super(message); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.