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] Add more details to ParserException #1600

Merged
merged 4 commits into from
Apr 7, 2019
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 @@ -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