Skip to content

Commit

Permalink
[Core] Don't swallow parse errors on the CLI (#2632)
Browse files Browse the repository at this point in the history
With v7.6.0 in 3bc80b9 before all and after
all hooks were introduced. This moved parsing of features into the execution
context. This resulted in any parse errors being swallowed with the assumption
that they would have been captured by the execution context already.

Fixes: #2631
  • Loading branch information
mpkorstanje authored Oct 31, 2022
1 parent 4af1850 commit 59195cd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ public static Builder builder() {
}

public void run() {
// Parse the features early. Don't proceed when there are lexer errors
List<Feature> features = featureSupplier.get();
context.startTestRun();
execute(() -> {
context.runBeforeAllHooks();
runFeatures();
runFeatures(features);
});
execute(context::runAfterAllHooks);
execute(context::finishTestRun);
Expand All @@ -98,8 +100,7 @@ private void execute(Runnable runnable) {
}
}

private void runFeatures() {
List<Feature> features = featureSupplier.get();
private void runFeatures(List<Feature> features) {
features.forEach(context::beforeFeature);
List<Future<?>> executingPickles = features.stream()
.flatMap(feature -> feature.getPickles().stream())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.cucumber.core.exception.CompositeCucumberException;
import io.cucumber.core.feature.TestFeatureParser;
import io.cucumber.core.gherkin.Feature;
import io.cucumber.core.gherkin.FeatureParserException;
import io.cucumber.core.options.RuntimeOptionsBuilder;
import io.cucumber.core.runner.StepDurationTimeService;
import io.cucumber.core.runner.TestBackendSupplier;
Expand Down Expand Up @@ -127,6 +128,17 @@ void with_ambiguous_scenarios() {
assertThat(runtime.exitStatus(), is(equalTo((byte) 0x1)));
}

@Test
void with_parse_error() {
Runtime runtime = Runtime.builder()
.withFeatureSupplier(() -> {
throw new FeatureParserException("oops");
})
.build();

assertThrows(FeatureParserException.class, runtime::run);
}

@Test
void should_pass_if_no_features_are_found() {
Runtime runtime = Runtime.builder()
Expand Down

0 comments on commit 59195cd

Please sign in to comment.