Skip to content

Commit

Permalink
Ability to specify line numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Apr 23, 2012
1 parent 5046b9b commit c7c4b85
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 19 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [Git master](https://github.com/cucumber/cucumber-jvm/compare/v1.0.3...master)

* [Core] Ability to specify line numbers: `@Cucumber.Options(features = "my/nice.feature:2:10")` ([#234](https://github.com/cucumber/cucumber-jvm/issues/234) Aslak Hellesøy)
* [WebDriver] Improved example that shows how to reuse a driver for the entire JVM. (Aslak Hellesøy)
* [Core] Allow custom @XStreamConverter to be used on regular arguments - not just table arguments. (Aslak Hellesøy)
* [Groovy] fixed & simplified groovy step snippets ([#303](https://github.com/cucumber/cucumber-jvm/pull/303) Martin Hauner)
Expand Down
18 changes: 6 additions & 12 deletions core/src/main/java/cucumber/runtime/RuntimeOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class RuntimeOptions {
public File dotCucumber;
public boolean dryRun;
public boolean strict = false;
public List<String> tags = new ArrayList<String>();
public List<Object> filters = new ArrayList<Object>();
public List<Formatter> formatters = new ArrayList<Formatter>();
public List<String> featurePaths = new ArrayList<String>();
private boolean monochrome = false;
Expand Down Expand Up @@ -63,7 +63,7 @@ private void parse(ArrayList<String> args) {
String gluePath = args.remove(0);
glue.add(gluePath);
} else if (arg.equals("--tags") || arg.equals("-t")) {
tags.add(args.remove(0));
filters.add(args.remove(0));
} else if (arg.equals("--format") || arg.equals("-f")) {
formatters.add(formatterConverter.convert(args.remove(0)));
} else if (arg.equals("--dotcucumber")) {
Expand All @@ -75,14 +75,15 @@ private void parse(ArrayList<String> args) {
} else if (arg.equals("--monochrome") || arg.equals("-m")) {
monochrome = true;
} else {
// TODO: Use PathWithLines and add line filter if any
featurePaths.add(arg);
PathWithLines pathWithLines = new PathWithLines(arg);
featurePaths.add(pathWithLines.path);
filters.addAll(pathWithLines.lines);
}
}
}

public List<CucumberFeature> cucumberFeatures(ResourceLoader resourceLoader) {
return load(resourceLoader, featurePaths, filters());
return load(resourceLoader, featurePaths, filters);
}

public Formatter formatter(ClassLoader classLoader) {
Expand Down Expand Up @@ -110,11 +111,4 @@ public Object invoke(Object target, Method method, Object[] args) throws Throwab
}
});
}

private List<Object> filters() {
List<Object> filters = new ArrayList<Object>();
filters.addAll(tags);
// TODO: Add lines and patterns (names)
return filters;
}
}
6 changes: 3 additions & 3 deletions examples/java-helloworld/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>info.cukes</groupId>
<artifactId>java-helloworld</artifactId>
<version>1.0.3</version>
<version>1.0.4-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Examples: Java Hello World</name>

Expand All @@ -27,13 +27,13 @@
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.0.2</version>
<version>1.0.4-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.0.2</version>
<version>1.0.4-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
8 changes: 4 additions & 4 deletions junit/src/main/java/cucumber/junit/Cucumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public Cucumber(Class clazz) throws InitializationError, IOException {
RuntimeOptions runtimeOptions = runtimeOptionsFactory.create();
runtime = new Runtime(resourceLoader, classLoader, runtimeOptions);

jUnitReporter = new JUnitReporter(runtimeOptions.reporter(classLoader), runtimeOptions.formatter(classLoader)
, runtimeOptions.strict);
jUnitReporter = new JUnitReporter(runtimeOptions.reporter(classLoader), runtimeOptions.formatter(classLoader), runtimeOptions.strict);
addChildren(runtimeOptions.cucumberFeatures(resourceLoader));
}

Expand Down Expand Up @@ -120,7 +119,8 @@ private void addChildren(List<CucumberFeature> cucumberFeatures) throws Initiali
boolean dryRun() default false;

/**
* Scenarios fail if
* Scenarios fail if
*
* @return
*/
boolean strict() default false;
Expand All @@ -136,7 +136,7 @@ private void addChildren(List<CucumberFeature> cucumberFeatures) throws Initiali
String[] glue() default {};

/**
* @return what tags in the feature should be executed
* @return what tags in the features should be executed
*/
String[] tags() default {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
//@Cucumber.Options(features = "cucumber/runtime/java/picocontainer/dates.feature:2:10")
public class RunCukesTest {
}
18 changes: 18 additions & 0 deletions picocontainer/src/test/resources/.cucumber/stepdefs.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@
}
]
},
{
"name": "the date should be Mar 1 2013",
"args": [
{
"offset": 19,
"val": "Mar 1 2013"
}
]
},
{
"name": "the date should be Oct 25 2011",
"args": [
Expand All @@ -147,6 +156,15 @@
"val": "2012-03-01T06:54:14"
}
]
},
{
"name": "the iso calendar is 2013-03-01T06:54:14",
"args": [
{
"offset": 20,
"val": "2013-03-01T06:54:14"
}
]
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ Feature: Dates
Scenario: An ISO 8601 date as Calendar
Given the iso calendar is 2012-03-01T06:54:14
Then the date should be Mar 1 2012

Scenario: Another ISO 8601 date as Calendar
Given the iso calendar is 2013-03-01T06:54:14
Then the date should be Mar 1 2013

6 comments on commit c7c4b85

@czulehner
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing a Cucumber-JVM Junit Test fails with a ClassCastException as the given line-number makes it into the filters Object-Array as Long (from class PathWithLines) and the gherkin.TagExpresison only handles Strings ??

java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String
    at gherkin.TagExpression.<init>(TagExpression.java:16)
    at gherkin.formatter.TagFilter.<init>(TagFilter.java:14)
    at gherkin.formatter.FilterFormatter.detectFilter(FilterFormatter.java:54)
    at gherkin.formatter.FilterFormatter.<init>(FilterFormatter.java:39)
    at cucumber.runtime.FeatureBuilder.parse(FeatureBuilder.java:108)
    at cucumber.runtime.model.CucumberFeature.load(CucumberFeature.java:40)
    at cucumber.runtime.RuntimeOptions.cucumberFeatures(RuntimeOptions.java:86)
    at cucumber.junit.Cucumber.<init>(Cucumber.java:60)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Am I missing something?

@aslakhellesoy
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I reproduce this? Are you passing both tags and line numbers?

@czulehner
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good hint!

Yes, I passed in both, tags and a line number:

@RunWith(Cucumber.class)
@Cucumber.Options(format = {"pretty", "html:target/cucumber"},
    features = {"tree/Maintenance/SalutationMaintenance.feature:16"},
    tags = {"~@Obsolete", "~@Manual"},
    glue = {" ... "}, 
    monochrome = true)
public class MaintenanceFeaturesTest
{
  ....

After removing the tags-Option it works, so this seems to be ok for me now,
but maybe adding a line of documentation in Cucumber.Options would help :-)
Or implementing a check to raise an error if specifiying both the tags option and adding a line number...

@aslakhellesoy
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'll add that. It needs to go into gherkin

@restagner
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm encountering a similar issue to the one noted by @czulehner. In my case, the Cucumber.Options look like

@RunWith(Cucumber.class)
@Cucumber.Options(
        features = { "src/test/resources/features/se_drag_n_drop.feature:4" }
        , monochrome = true
        , format = {"pretty", "html:target/results" }
        , glue = { "org.stag.hello" }
        , tags = { "@drag_n_drop" })
public class HelloTest {
}

This produces the following exception when it's executed. Is using the 'tags' option, in combination with the feature + line number option something I should avoid?

java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String
    at gherkin.TagExpression.<init>(TagExpression.java:16)
    at gherkin.formatter.TagFilter.<init>(TagFilter.java:14)
    at gherkin.formatter.FilterFormatter.detectFilter(FilterFormatter.java:54)
    at gherkin.formatter.FilterFormatter.<init>(FilterFormatter.java:39)
    at cucumber.runtime.FeatureBuilder.parse(FeatureBuilder.java:108)
    at cucumber.runtime.model.CucumberFeature.load(CucumberFeature.java:40)
    at cucumber.runtime.RuntimeOptions.cucumberFeatures(RuntimeOptions.java:86)
    at cucumber.junit.Cucumber.<init>(Cucumber.java:61)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

@aslakhellesoy
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. You can specify tags or line numbers, but not both. I'll create a ticket.

Please sign in to comment.