Skip to content

Commit

Permalink
[Core] Add more details to ParserException (#1600)
Browse files Browse the repository at this point in the history
Added resource path to the exception thrown in `FeatureParser.parseResource` to allow user to see which file failed to parse.
  • Loading branch information
zutshiy authored and mpkorstanje committed Apr 7, 2019
1 parent 6596761 commit e117065
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static CucumberFeature parseResource(Resource resource) {
List<PickleEvent> pickleEvents = compilePickles(gherkinDocument, resource);
return new CucumberFeature(gherkinDocument, path, source, pickleEvents);
} catch (ParserException e) {
throw new CucumberException(e);
throw new CucumberException("Failed to parse resource at: " + path.toString(), e);
}
}

Expand Down
22 changes: 11 additions & 11 deletions junit/src/test/java/cucumber/runtime/junit/CucumberTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import cucumber.runtime.CucumberException;
import gherkin.ParserException.CompositeParserException;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.ParallelComputer;
import org.junit.rules.ExpectedException;
import org.junit.runner.Description;
import org.junit.runner.Request;
import org.junit.runner.RunWith;
Expand All @@ -18,20 +21,21 @@
import org.mockito.Mockito;

import java.io.File;
import java.io.IOException;
import java.util.List;

import static java.util.Collections.emptyList;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.isA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.mockito.ArgumentMatchers.argThat;

public class CucumberTest {

@Rule
public ExpectedException thrownException = ExpectedException.none();
private String dir;

@Before
Expand Down Expand Up @@ -62,15 +66,11 @@ public void finds_features_based_on_explicit_root_package() throws Initializatio
assertEquals("Feature: Feature A", cucumber.getChildren().get(0).getName());
}

@Test
public void testThatParsingErrorsIsNicelyReported() throws Exception {
try {
new Cucumber(LexerErrorFeature.class);
fail("Expecting error");
} catch (CucumberException e) {
assertThat(e.getMessage(), startsWith("gherkin.ParserException$CompositeParserException: Parser errors:"));
}
}
@Test
public void testThatParsingErrorsIsNicelyReported() throws Exception {
thrownException.expectCause(isA(CompositeParserException.class));
new Cucumber(LexerErrorFeature.class);
}

@Test
public void testThatFileIsNotCreatedOnParsingError() throws Exception {
Expand Down

0 comments on commit e117065

Please sign in to comment.