Skip to content
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

Modified Runtime Options to split cucumber.options on words ignoring spaces in single quotes #429

Merged
merged 1 commit into from
Nov 28, 2012
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
18 changes: 16 additions & 2 deletions core/src/main/java/cucumber/runtime/RuntimeOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,7 +41,7 @@ public RuntimeOptions(Properties properties, String... argv) {

parse(new ArrayList<String>(asList(argv)));
if (properties.containsKey("cucumber.options")) {
parse(new ArrayList<String>(asList(properties.getProperty("cucumber.options").split(" "))));
parse(cucumberOptionsSplit(properties.getProperty("cucumber.options")));
}

if (formatters.isEmpty()) {
Expand All @@ -54,7 +55,20 @@ public RuntimeOptions(Properties properties, String... argv) {
}
}

private void parse(List<String> args) {
private List<String> cucumberOptionsSplit(String property) {
List<String> matchList = new ArrayList<String>();
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<String> args) {
List<Object> parsedFilters = new ArrayList<Object>();
while (!args.isEmpty()) {
String arg = args.remove(0);
Expand Down
34 changes: 33 additions & 1 deletion core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package cucumber.runtime;

import net.sourceforge.cobertura.ant.Regex;

import org.junit.Test;

import java.io.File;
Expand Down Expand Up @@ -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";
Expand Down