From 59195cd1dfd6a5b92e7b682d512ec6953c8faf66 Mon Sep 17 00:00:00 2001 From: "M.P. Korstanje" Date: Mon, 31 Oct 2022 16:15:08 +0100 Subject: [PATCH] [Core] Don't swallow parse errors on the CLI (#2632) With v7.6.0 in 3bc80b964971f9a61f6d22d6fe772499edbb8933 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 --- .../main/java/io/cucumber/core/runtime/Runtime.java | 7 ++++--- .../java/io/cucumber/core/runtime/RuntimeTest.java | 12 ++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) 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()