Skip to content

Clobber all filter types when override one filter type in the environment options #748

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

Merged
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
24 changes: 23 additions & 1 deletion core/src/main/java/cucumber/runtime/RuntimeOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import cucumber.runtime.formatter.StrictAware;
import cucumber.runtime.io.ResourceLoader;
import cucumber.runtime.model.CucumberFeature;
import cucumber.runtime.model.PathWithLines;
import gherkin.formatter.Formatter;
import gherkin.formatter.Reporter;
import gherkin.util.FixJava;
Expand Down Expand Up @@ -129,9 +130,12 @@ private void parse(List<String> args) {
parsedFeaturePaths.add(arg);
}
}
if (!parsedFilters.isEmpty()) {
if (!parsedFilters.isEmpty() || haveLineFilters(parsedFeaturePaths)) {
filters.clear();
filters.addAll(parsedFilters);
if (parsedFeaturePaths.isEmpty() && !featurePaths.isEmpty()) {
stripLinesFromFeaturePaths(featurePaths);
}
}
if (!parsedFeaturePaths.isEmpty()) {
featurePaths.clear();
Expand All @@ -143,6 +147,24 @@ private void parse(List<String> args) {
}
}

private boolean haveLineFilters(List<String> parsedFeaturePaths) {
for (String pathName : parsedFeaturePaths) {
if (pathName.startsWith("@") || PathWithLines.hasLineFilters(pathName)) {
return true;
}
}
return false;
}

private void stripLinesFromFeaturePaths(List<String> featurePaths) {
List<String> newPaths = new ArrayList<String>();
for (String pathName : featurePaths) {
newPaths.add(PathWithLines.stripLineFilters(pathName));
}
featurePaths.clear();
featurePaths.addAll(newPaths);
}

private void printUsage() {
System.out.println(USAGE);
}
Expand Down
13 changes: 13 additions & 0 deletions core/src/main/java/cucumber/runtime/model/PathWithLines.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ public class PathWithLines {
public final String path;
public final List<Long> lines = new ArrayList<Long>();

public static boolean hasLineFilters(String pathName) {
return FILE_COLON_LINE_PATTERN.matcher(pathName).matches();
}

public static String stripLineFilters(String pathName) {
Matcher matcher = FILE_COLON_LINE_PATTERN.matcher(pathName);
if (matcher.matches()) {
return matcher.group(1);
} else {
return pathName;
}
}

public PathWithLines(String pathName) {
Matcher matcher = FILE_COLON_LINE_PATTERN.matcher(pathName);
if (matcher.matches()) {
Expand Down
24 changes: 24 additions & 0 deletions core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,22 @@ public void clobbers_filters_from_cli_if_filters_specified_in_cucumber_options_p
assertEquals(asList("@clobber_with_this"), runtimeOptions.getFilters());
}

@Test
public void clobbers_tag_and_name_filters_from_cli_if_line_filters_specified_in_cucumber_options_property() {
Properties properties = new Properties();
properties.setProperty("cucumber.options", "path/file.feature:3");
RuntimeOptions runtimeOptions = new RuntimeOptions(new Env(properties), asList("--tags", "@should_be_clobbered", "--name", "should_be_clobbered"));
assertEquals(Collections.<Object>emptyList(), runtimeOptions.getFilters());
}

@Test
public void clobbers_tag_and_name_filters_from_cli_if_rerun_file_specified_in_cucumber_options_property() {
Properties properties = new Properties();
properties.setProperty("cucumber.options", "@rerun.txt");
RuntimeOptions runtimeOptions = new RuntimeOptions(new Env(properties), asList("--tags", "@should_be_clobbered", "--name", "should_be_clobbered"));
assertEquals(Collections.<Object>emptyList(), runtimeOptions.getFilters());
}

@Test
public void preserves_filters_from_cli_if_filters_not_specified_in_cucumber_options_property() {
Properties properties = new Properties();
Expand All @@ -184,6 +200,14 @@ public void clobbers_features_from_cli_if_features_specified_in_cucumber_options
assertEquals(asList("new", "newer"), runtimeOptions.getFeaturePaths());
}

@Test
public void strips_lines_from_features_from_cli_if_filters_are_specified_in_cucumber_options_property() {
Properties properties = new Properties();
properties.setProperty("cucumber.options", "--tags @Tag");
RuntimeOptions runtimeOptions = new RuntimeOptions(new Env(properties), asList("path/file.feature:3"));
assertEquals(asList("path/file.feature"), runtimeOptions.getFeaturePaths());
}

@Test
public void preserves_features_from_cli_if_features_not_specified_in_cucumber_options_property() {
Properties properties = new Properties();
Expand Down