diff --git a/core/src/main/java/cucumber/runtime/RuntimeOptions.java b/core/src/main/java/cucumber/runtime/RuntimeOptions.java index 109534c9a4..b9cc4e7ebf 100644 --- a/core/src/main/java/cucumber/runtime/RuntimeOptions.java +++ b/core/src/main/java/cucumber/runtime/RuntimeOptions.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.Properties; import java.util.ResourceBundle; +import java.util.regex.Matcher; import java.util.regex.Pattern; import static cucumber.runtime.model.CucumberFeature.load; @@ -40,7 +41,7 @@ public RuntimeOptions(Properties properties, String... argv) { parse(new ArrayList(asList(argv))); if (properties.containsKey("cucumber.options")) { - parse(new ArrayList(asList(properties.getProperty("cucumber.options").split(" ")))); + parse(cucumberOptionsSplit(properties.getProperty("cucumber.options"))); } if (formatters.isEmpty()) { @@ -54,7 +55,20 @@ public RuntimeOptions(Properties properties, String... argv) { } } - private void parse(List args) { + private List cucumberOptionsSplit(String property) { + List matchList = new ArrayList(); + Pattern regex = Pattern.compile("[^\\s']+|'([^']*)'"); + Matcher regexMatcher = regex.matcher(property); + while (regexMatcher.find()) { + if (regexMatcher.group(1) != null) + matchList.add(regexMatcher.group(1)); + else + matchList.add(regexMatcher.group()); + } + return matchList; + } + + private void parse(List args) { List parsedFilters = new ArrayList(); while (!args.isEmpty()) { String arg = args.remove(0); diff --git a/core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java b/core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java index e4a2d88280..adf22253de 100644 --- a/core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java +++ b/core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java @@ -1,5 +1,7 @@ package cucumber.runtime; +import net.sourceforge.cobertura.ant.Regex; + import org.junit.Test; import java.io.File; @@ -71,7 +73,37 @@ public void name() { Pattern actualPattern = (Pattern) options.filters.iterator().next(); assertEquals(someName, actualPattern.pattern()); } - + + @Test + public void name_with_spaces() { + String someName = "some Name"; + RuntimeOptions options = new RuntimeOptions(new Properties(), "--name", someName); + Pattern actualPattern = (Pattern) options.filters.iterator().next(); + assertEquals(someName, actualPattern.pattern()); + } + + @Test + public void ensure_name_with_spaces_works_with_cucumber_options() { + String someName = "some Name"; + Properties properties = new Properties(); + properties.setProperty("cucumber.options", "--name '" + someName + "'"); + RuntimeOptions options = new RuntimeOptions(properties); + Pattern actualPattern = (Pattern) options.filters.iterator().next(); + assertEquals(someName, actualPattern.pattern()); + } + + @Test + public void ensure_multiple_cucumber_options_with_spaces_parse_correctly() { + String someName = "some Name"; + String somePath = "some file\\path"; + Properties properties = new Properties(); + properties.setProperty("cucumber.options", "--name '" + someName + "'" + " --dotcucumber '" + somePath + "'"); + RuntimeOptions options = new RuntimeOptions(properties); + Pattern actualPattern = (Pattern) options.filters.iterator().next(); + assertEquals(someName, actualPattern.pattern()); + assertEquals(new File(somePath), options.dotCucumber); + } + @Test public void name_short() { String someName = "someName";