Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Exception when using pretty print #171

Merged
merged 1 commit into from

3 participants

@mattnathan

Given a step like:
@Given("^(it has )?some value$")

And a feature file like:
Given I have something
And it has some value
And some value

The old code would throw an exception when running pretty print mode (found via cucumber-jvm and @Cucumner.Options(format="pretty")

@mattnathan

Forgot to say, I haven't managed to test the change because I couldn't get the code to build on my machine so tread carefully.

@dkowis
Collaborator

I wonder if this is the same problem I'm encountering in something else. I'm having an exception when using pretty print mode from the CLI.

I shall investigate.

@dkowis
Collaborator

By any chance was this similar to your exception: cucumber/cucumber-jvm#280 ?

@dkowis
Collaborator

Hm, so incorporating this change didn't fix the problem for me, so I can't vouch for it. Of course, my problem might be significantly different than yours.

@mattnathan

So that exception is not the same as the one I was getting, I will try to get my exception and pull together a more comprehensive set of tests (and try to get the thing building)

@mattnathan
java.lang.reflect.UndeclaredThrowableException
    at $Proxy11.match(Unknown Source)
    at cucumber.junit.JUnitReporter.match(JUnitReporter.java:54)
    at cucumber.runtime.Runtime.runStep(Runtime.java:203)
    at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
    at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
    at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:32)
    at cucumber.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:69)
    at cucumber.junit.FeatureRunner.runChild(FeatureRunner.java:65)
    at cucumber.junit.FeatureRunner.runChild(FeatureRunner.java:20)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at cucumber.junit.FeatureRunner.run(FeatureRunner.java:72)
    at cucumber.junit.Cucumber.runChild(Cucumber.java:75)
    at cucumber.junit.Cucumber.runChild(Cucumber.java:36)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at cucumber.junit.Cucumber.run(Cucumber.java:80)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:62)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at cucumber.runtime.RuntimeOptions$2.invoke(RuntimeOptions.java:103)
    ... 29 more
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.String.substring(String.java:1937)
    at gherkin.formatter.StepPrinter.writeStep(StepPrinter.java:10)
    at gherkin.formatter.PrettyFormatter.printStep(PrettyFormatter.java:212)
    at gherkin.formatter.PrettyFormatter.match(PrettyFormatter.java:179)
    ... 34 more

Here is the exception I am getting

@mattnathan

The output printed by cucumber is:

  Scenario: Passes the same instance to both step classes                       # features/StepsTest.feature:5
    Given I have a document                                                     # DocumentSteps.addDocument()
      And it is named TestDocument                                              # NamedSteps.setLastRequestName(String,String)
      And     Given I have a request
      And it has an Accept header of text/plain
    ...

when the original file is

  Scenario: Passes the same instance to both step classes
    Given I have a document
      And it is named TestDocument
      And is loaded from /cucumber-guice.properties
    Given I have a request
      And it has an Accept header of text/plain
    ...

The pattern that is being matched looks like this:

"^(it )?is loaded from ([^?#\s]+)$"
@mattnathan

I tried to get it building but it just won't generate the i18n java classes so I can't build it. Sorry, I couldn't think of anything else to try.

@aslakhellesoy aslakhellesoy merged commit ba4b8f0 into cucumber:master
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.
Showing with 7 additions and 3 deletions.
  1. +7 −3 java/src/main/java/gherkin/formatter/StepPrinter.java
View
10 java/src/main/java/gherkin/formatter/StepPrinter.java
@@ -6,13 +6,17 @@
public void writeStep(NiceAppendable out, Format textFormat, Format argFormat, String stepName, List<Argument> arguments) {
int textStart = 0;
for (Argument argument : arguments) {
- if (argument.getOffset() != 0) {
+ // can be -1 if the argument is missing.
+ if (argument.getOffset() > 0) {
String text = stepName.substring(textStart, argument.getOffset());
out.append(textFormat.text(text));
}
String val = argument.getVal();
- out.append(argFormat.text(val));
- textStart = argument.getOffset() + argument.getVal().length();
+ // val can be null if the argument isn't there, for example @And("(it )?has something")
+ if (val != null) {
+ out.append(argFormat.text(val));
+ textStart = argument.getOffset() + argument.getVal().length();
+ }
}
if (textStart != stepName.length()) {
String text = stepName.substring(textStart, stepName.length());
Something went wrong with that request. Please try again.