Skip to content

Commit 59195cd

Browse files
authored
[Core] Don't swallow parse errors on the CLI (#2632)
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
1 parent 4af1850 commit 59195cd

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

cucumber-core/src/main/java/io/cucumber/core/runtime/Runtime.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,12 @@ public static Builder builder() {
7676
}
7777

7878
public void run() {
79+
// Parse the features early. Don't proceed when there are lexer errors
80+
List<Feature> features = featureSupplier.get();
7981
context.startTestRun();
8082
execute(() -> {
8183
context.runBeforeAllHooks();
82-
runFeatures();
84+
runFeatures(features);
8385
});
8486
execute(context::runAfterAllHooks);
8587
execute(context::finishTestRun);
@@ -98,8 +100,7 @@ private void execute(Runnable runnable) {
98100
}
99101
}
100102

101-
private void runFeatures() {
102-
List<Feature> features = featureSupplier.get();
103+
private void runFeatures(List<Feature> features) {
103104
features.forEach(context::beforeFeature);
104105
List<Future<?>> executingPickles = features.stream()
105106
.flatMap(feature -> feature.getPickles().stream())

cucumber-core/src/test/java/io/cucumber/core/runtime/RuntimeTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.cucumber.core.exception.CompositeCucumberException;
1111
import io.cucumber.core.feature.TestFeatureParser;
1212
import io.cucumber.core.gherkin.Feature;
13+
import io.cucumber.core.gherkin.FeatureParserException;
1314
import io.cucumber.core.options.RuntimeOptionsBuilder;
1415
import io.cucumber.core.runner.StepDurationTimeService;
1516
import io.cucumber.core.runner.TestBackendSupplier;
@@ -127,6 +128,17 @@ void with_ambiguous_scenarios() {
127128
assertThat(runtime.exitStatus(), is(equalTo((byte) 0x1)));
128129
}
129130

131+
@Test
132+
void with_parse_error() {
133+
Runtime runtime = Runtime.builder()
134+
.withFeatureSupplier(() -> {
135+
throw new FeatureParserException("oops");
136+
})
137+
.build();
138+
139+
assertThrows(FeatureParserException.class, runtime::run);
140+
}
141+
130142
@Test
131143
void should_pass_if_no_features_are_found() {
132144
Runtime runtime = Runtime.builder()

0 commit comments

Comments
 (0)