Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix for Lexing Error message not useful #523

Merged
merged 1 commit into from

2 participants

@ggili

Hi Guys,

Please find my contribution for improving the error message in case a feature file has errors.

@aslakhellesoy aslakhellesoy merged commit 10ba032 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
6 core/src/main/java/cucumber/runtime/FeatureBuilder.java
@@ -110,7 +110,11 @@ public void parse(Resource resource, List<Object> filters) {
}
Parser parser = new Parser(formatter);
- parser.parse(gherkin, resource.getPath(), 0);
+ try {
+ parser.parse(gherkin, resource.getPath(), 0);
+ } catch (Exception e) {
+ throw new CucumberException(String.format("Error parsing feature file %s", resource.getPath()), e);
+ }
I18n i18n = parser.getI18nLanguage();
if (currentCucumberFeature != null) {
// The current feature may be null if we used a very restrictive filter, say a tag that isn't used.
View
16 junit/src/test/java/cucumber/runtime/junit/CucumberTest.java
@@ -13,6 +13,7 @@
import java.io.IOException;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
public class CucumberTest {
@@ -46,6 +47,16 @@ public void finds_features_based_on_explicit_root_package() throws IOException,
assertEquals("Feature: FA", cucumber.getChildren().get(0).getName());
}
+ @Test
+ public void testThatParsingErrorsIsNicelyReported() throws Exception {
+ try {
+ new Cucumber(LexerErrorFeature.class);
+ fail("Expecting error");
+ } catch (CucumberException e) {
+ assertEquals("Error parsing feature file cucumber/runtime/error/lexer_error.feature", e.getMessage());
+ }
+ }
+
@Test(expected = CucumberException.class)
public void finds_no_features_when_explicit_package_has_nothnig() throws IOException, InitializationError {
new Cucumber(ExplicitFeaturePathWithNoFeatures.class);
@@ -89,4 +100,9 @@ public void no_stepdefs_in_cucumber_runner_invalid() {
@Cucumber.Options(features = {"classpath:gibber/ish"})
private class ExplicitFeaturePathWithNoFeatures {
}
+
+ @Cucumber.Options(features = {"classpath:cucumber/runtime/error/lexer_error.feature"})
+ private class LexerErrorFeature {
+
+ }
}
View
6 junit/src/test/resources/cucumber/runtime/error/lexer_error.feature
@@ -0,0 +1,6 @@
+Feature FA
+
+ Scenario SA
+ Given GA
+ When GA
+ Then TA
Something went wrong with that request. Please try again.