From 81ff90e3e830cecb87ae248b3dc900ddf52cace6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Rasmusson?= Date: Tue, 1 Jul 2014 19:56:32 +0200 Subject: [PATCH 1/2] Clobber tag and name filters if paths with lines are specified --- .../java/cucumber/runtime/RuntimeOptions.java | 12 +++++++++++- .../cucumber/runtime/model/PathWithLines.java | 4 ++++ .../cucumber/runtime/RuntimeOptionsTest.java | 16 ++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/cucumber/runtime/RuntimeOptions.java b/core/src/main/java/cucumber/runtime/RuntimeOptions.java index 97df55550c..cbad3e5c60 100644 --- a/core/src/main/java/cucumber/runtime/RuntimeOptions.java +++ b/core/src/main/java/cucumber/runtime/RuntimeOptions.java @@ -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; @@ -129,7 +130,7 @@ private void parse(List args) { parsedFeaturePaths.add(arg); } } - if (!parsedFilters.isEmpty()) { + if (!parsedFilters.isEmpty() || haveLineFilters(parsedFeaturePaths)) { filters.clear(); filters.addAll(parsedFilters); } @@ -143,6 +144,15 @@ private void parse(List args) { } } + private boolean haveLineFilters(List parsedFeaturePaths) { + for (String pathName : parsedFeaturePaths) { + if (pathName.startsWith("@") || PathWithLines.hasLineFilters(pathName)) { + return true; + } + } + return false; + } + private void printUsage() { System.out.println(USAGE); } diff --git a/core/src/main/java/cucumber/runtime/model/PathWithLines.java b/core/src/main/java/cucumber/runtime/model/PathWithLines.java index ca29911eeb..90bf17fb87 100644 --- a/core/src/main/java/cucumber/runtime/model/PathWithLines.java +++ b/core/src/main/java/cucumber/runtime/model/PathWithLines.java @@ -11,6 +11,10 @@ public class PathWithLines { public final String path; public final List lines = new ArrayList(); + public static boolean hasLineFilters(String pathName) { + return FILE_COLON_LINE_PATTERN.matcher(pathName).matches(); + } + public PathWithLines(String pathName) { Matcher matcher = FILE_COLON_LINE_PATTERN.matcher(pathName); if (matcher.matches()) { diff --git a/core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java b/core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java index 40a489a50a..5be2447c71 100644 --- a/core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java +++ b/core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java @@ -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.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.emptyList(), runtimeOptions.getFilters()); + } + @Test public void preserves_filters_from_cli_if_filters_not_specified_in_cucumber_options_property() { Properties properties = new Properties(); From df03361551d7e3ce06619ccdf2c5df584bad5cef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Rasmusson?= Date: Tue, 1 Jul 2014 20:15:29 +0200 Subject: [PATCH 2/2] Strip lines from feature paths if filters are specified --- .../main/java/cucumber/runtime/RuntimeOptions.java | 12 ++++++++++++ .../java/cucumber/runtime/model/PathWithLines.java | 9 +++++++++ .../java/cucumber/runtime/RuntimeOptionsTest.java | 8 ++++++++ 3 files changed, 29 insertions(+) diff --git a/core/src/main/java/cucumber/runtime/RuntimeOptions.java b/core/src/main/java/cucumber/runtime/RuntimeOptions.java index cbad3e5c60..5bc0ed35d5 100644 --- a/core/src/main/java/cucumber/runtime/RuntimeOptions.java +++ b/core/src/main/java/cucumber/runtime/RuntimeOptions.java @@ -133,6 +133,9 @@ private void parse(List args) { if (!parsedFilters.isEmpty() || haveLineFilters(parsedFeaturePaths)) { filters.clear(); filters.addAll(parsedFilters); + if (parsedFeaturePaths.isEmpty() && !featurePaths.isEmpty()) { + stripLinesFromFeaturePaths(featurePaths); + } } if (!parsedFeaturePaths.isEmpty()) { featurePaths.clear(); @@ -153,6 +156,15 @@ private boolean haveLineFilters(List parsedFeaturePaths) { return false; } + private void stripLinesFromFeaturePaths(List featurePaths) { + List newPaths = new ArrayList(); + for (String pathName : featurePaths) { + newPaths.add(PathWithLines.stripLineFilters(pathName)); + } + featurePaths.clear(); + featurePaths.addAll(newPaths); + } + private void printUsage() { System.out.println(USAGE); } diff --git a/core/src/main/java/cucumber/runtime/model/PathWithLines.java b/core/src/main/java/cucumber/runtime/model/PathWithLines.java index 90bf17fb87..4a1e06297b 100644 --- a/core/src/main/java/cucumber/runtime/model/PathWithLines.java +++ b/core/src/main/java/cucumber/runtime/model/PathWithLines.java @@ -15,6 +15,15 @@ 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()) { diff --git a/core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java b/core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java index 5be2447c71..5226529d8c 100644 --- a/core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java +++ b/core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java @@ -200,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();