diff --git a/cucumber-core/src/main/java/io/cucumber/core/runtime/Runtime.java b/cucumber-core/src/main/java/io/cucumber/core/runtime/Runtime.java index 371dd31588..c70fc2f965 100644 --- a/cucumber-core/src/main/java/io/cucumber/core/runtime/Runtime.java +++ b/cucumber-core/src/main/java/io/cucumber/core/runtime/Runtime.java @@ -76,10 +76,12 @@ public static Builder builder() { } public void run() { + // Parse the features early. Don't proceed when there are lexer errors + List features = featureSupplier.get(); context.startTestRun(); execute(() -> { context.runBeforeAllHooks(); - runFeatures(); + runFeatures(features); }); execute(context::runAfterAllHooks); execute(context::finishTestRun); @@ -98,8 +100,7 @@ private void execute(Runnable runnable) { } } - private void runFeatures() { - List features = featureSupplier.get(); + private void runFeatures(List features) { features.forEach(context::beforeFeature); List> executingPickles = features.stream() .flatMap(feature -> feature.getPickles().stream()) diff --git a/cucumber-core/src/test/java/io/cucumber/core/runtime/RuntimeTest.java b/cucumber-core/src/test/java/io/cucumber/core/runtime/RuntimeTest.java index f552209889..ea4b0ac64b 100644 --- a/cucumber-core/src/test/java/io/cucumber/core/runtime/RuntimeTest.java +++ b/cucumber-core/src/test/java/io/cucumber/core/runtime/RuntimeTest.java @@ -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; @@ -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()