Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Don't swallow parse errors on the CLI #2632

Merged
merged 1 commit into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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