Skip to content

Commit 916d6c1

Browse files
committed
Attribution for #748
2 parents 97da422 + df03361 commit 916d6c1

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

History.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
## [1.2.0-SNAPSHOT (Git master)](https://github.com/cucumber/cucumber-jvm/compare/v1.1.8...master) (Not released)
22

3+
* [Core] Clobber all filter types when override one filter type in the environment options ([#748](https://github.com/cucumber/cucumber-jvm/pull/748) Björn Rasmusson)
34
* [Android] Big refactoring ([#766](https://github.com/cucumber/cucumber-jvm/pull/766) Sebastian Gröbler)
45
* [Android] Improve documentation ([#772](https://github.com/cucumber/cucumber-jvm/pull/772) K76154)
56
* [Core] New --i18n option for printing keywords ([#785](https://github.com/cucumber/cucumber-jvm/pull/785) Seb Rose)
6-
* [Core] Make the JUnit formatter handle empty scenarios ([#774](https://github.com/cucumber/cucumber-jvm/issues/774) Björn Rasmusson).
7+
* [Core] Make the JUnit formatter handle empty scenarios ([#774](https://github.com/cucumber/cucumber-jvm/issues/774) Björn Rasmusson)
78
* [Scala] Fixing randomly failing tests in the Scala module ([#768](https://github.com/cucumber/cucumber-jvm/pull/768), [#761](https://github.com/cucumber/cucumber-jvm/issues/761) Manuel Bernhardt)
89
* [JRuby] cucumber-jruby backend fails to build when `RUBY_VERSION` is present in environment ([#718](https://github.com/cucumber/cucumber-jvm/issues/718) Aslak Hellesøy)
910
* [Core] `DataTable.asMap()` returns a `LinkedHashMap`, ensuring key iteration order is the same as in the gherkin table ([#764](https://github.com/cucumber/cucumber-jvm/issues/764) Aslak Hellesøy).

core/src/main/java/cucumber/runtime/RuntimeOptions.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import cucumber.runtime.io.ResourceLoader;
99
import cucumber.runtime.model.CucumberFeature;
1010
import gherkin.I18n;
11+
import cucumber.runtime.model.PathWithLines;
1112
import gherkin.formatter.Formatter;
1213
import gherkin.formatter.Reporter;
1314
import gherkin.util.FixJava;
@@ -132,9 +133,12 @@ private void parse(List<String> args) {
132133
parsedFeaturePaths.add(arg);
133134
}
134135
}
135-
if (!parsedFilters.isEmpty()) {
136+
if (!parsedFilters.isEmpty() || haveLineFilters(parsedFeaturePaths)) {
136137
filters.clear();
137138
filters.addAll(parsedFilters);
139+
if (parsedFeaturePaths.isEmpty() && !featurePaths.isEmpty()) {
140+
stripLinesFromFeaturePaths(featurePaths);
141+
}
138142
}
139143
if (!parsedFeaturePaths.isEmpty()) {
140144
featurePaths.clear();
@@ -146,6 +150,24 @@ private void parse(List<String> args) {
146150
}
147151
}
148152

153+
private boolean haveLineFilters(List<String> parsedFeaturePaths) {
154+
for (String pathName : parsedFeaturePaths) {
155+
if (pathName.startsWith("@") || PathWithLines.hasLineFilters(pathName)) {
156+
return true;
157+
}
158+
}
159+
return false;
160+
}
161+
162+
private void stripLinesFromFeaturePaths(List<String> featurePaths) {
163+
List<String> newPaths = new ArrayList<String>();
164+
for (String pathName : featurePaths) {
165+
newPaths.add(PathWithLines.stripLineFilters(pathName));
166+
}
167+
featurePaths.clear();
168+
featurePaths.addAll(newPaths);
169+
}
170+
149171
private void printUsage() {
150172
System.out.println(USAGE);
151173
}

core/src/main/java/cucumber/runtime/model/PathWithLines.java

+13
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ public class PathWithLines {
1111
public final String path;
1212
public final List<Long> lines = new ArrayList<Long>();
1313

14+
public static boolean hasLineFilters(String pathName) {
15+
return FILE_COLON_LINE_PATTERN.matcher(pathName).matches();
16+
}
17+
18+
public static String stripLineFilters(String pathName) {
19+
Matcher matcher = FILE_COLON_LINE_PATTERN.matcher(pathName);
20+
if (matcher.matches()) {
21+
return matcher.group(1);
22+
} else {
23+
return pathName;
24+
}
25+
}
26+
1427
public PathWithLines(String pathName) {
1528
Matcher matcher = FILE_COLON_LINE_PATTERN.matcher(pathName);
1629
if (matcher.matches()) {

core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java

+24
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,22 @@ public void clobbers_filters_from_cli_if_filters_specified_in_cucumber_options_p
154154
assertEquals(asList("@clobber_with_this"), runtimeOptions.getFilters());
155155
}
156156

157+
@Test
158+
public void clobbers_tag_and_name_filters_from_cli_if_line_filters_specified_in_cucumber_options_property() {
159+
Properties properties = new Properties();
160+
properties.setProperty("cucumber.options", "path/file.feature:3");
161+
RuntimeOptions runtimeOptions = new RuntimeOptions(new Env(properties), asList("--tags", "@should_be_clobbered", "--name", "should_be_clobbered"));
162+
assertEquals(Collections.<Object>emptyList(), runtimeOptions.getFilters());
163+
}
164+
165+
@Test
166+
public void clobbers_tag_and_name_filters_from_cli_if_rerun_file_specified_in_cucumber_options_property() {
167+
Properties properties = new Properties();
168+
properties.setProperty("cucumber.options", "@rerun.txt");
169+
RuntimeOptions runtimeOptions = new RuntimeOptions(new Env(properties), asList("--tags", "@should_be_clobbered", "--name", "should_be_clobbered"));
170+
assertEquals(Collections.<Object>emptyList(), runtimeOptions.getFilters());
171+
}
172+
157173
@Test
158174
public void preserves_filters_from_cli_if_filters_not_specified_in_cucumber_options_property() {
159175
Properties properties = new Properties();
@@ -170,6 +186,14 @@ public void clobbers_features_from_cli_if_features_specified_in_cucumber_options
170186
assertEquals(asList("new", "newer"), runtimeOptions.getFeaturePaths());
171187
}
172188

189+
@Test
190+
public void strips_lines_from_features_from_cli_if_filters_are_specified_in_cucumber_options_property() {
191+
Properties properties = new Properties();
192+
properties.setProperty("cucumber.options", "--tags @Tag");
193+
RuntimeOptions runtimeOptions = new RuntimeOptions(new Env(properties), asList("path/file.feature:3"));
194+
assertEquals(asList("path/file.feature"), runtimeOptions.getFeaturePaths());
195+
}
196+
173197
@Test
174198
public void preserves_features_from_cli_if_features_not_specified_in_cucumber_options_property() {
175199
Properties properties = new Properties();

0 commit comments

Comments
 (0)