Skip to content

Commit 42ee985

Browse files
committed
Make tests slightly more readable. Follow coding conventions. Closes #379
1 parent ecdbd77 commit 42ee985

File tree

3 files changed

+32
-42
lines changed

3 files changed

+32
-42
lines changed

History.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
##
2+
3+
* [Core] Scenario --name not working for names with quotes and multiple words ([#379](https://github.com/cucumber/cucumber-jvm/issues/379), [#429](https://github.com/cucumber/cucumber-jvm/pull/429) William Powell)
4+
15
## [1.1.1](https://github.com/cucumber/cucumber-jvm/compare/v1.0.14...1.1.1)
26

37
This release bumps the minor version number from 1.0 to 1.1. This is because there are backwards-incompatible changes.

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

+13-12
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
public class RuntimeOptions {
2626
public static final String VERSION = ResourceBundle.getBundle("cucumber.version").getString("cucumber-jvm.version");
2727
public static final String USAGE = FixJava.readResource("/cucumber/runtime/USAGE.txt");
28+
private static final Pattern SHELLWORDS_PATTERN = Pattern.compile("[^\\s']+|'([^']*)'");
2829

2930
public final List<String> glue = new ArrayList<String>();
3031
public final List<Object> filters = new ArrayList<Object>();
@@ -56,19 +57,19 @@ public RuntimeOptions(Properties properties, String... argv) {
5657
}
5758

5859
private List<String> cucumberOptionsSplit(String property) {
59-
List<String> matchList = new ArrayList<String>();
60-
Pattern regex = Pattern.compile("[^\\s']+|'([^']*)'");
61-
Matcher regexMatcher = regex.matcher(property);
62-
while (regexMatcher.find()) {
63-
if (regexMatcher.group(1) != null)
64-
matchList.add(regexMatcher.group(1));
65-
else
66-
matchList.add(regexMatcher.group());
67-
}
68-
return matchList;
69-
}
60+
List<String> matchList = new ArrayList<String>();
61+
Matcher shellwordsMatcher = SHELLWORDS_PATTERN.matcher(property);
62+
while (shellwordsMatcher.find()) {
63+
if (shellwordsMatcher.group(1) != null) {
64+
matchList.add(shellwordsMatcher.group(1));
65+
} else {
66+
matchList.add(shellwordsMatcher.group());
67+
}
68+
}
69+
return matchList;
70+
}
7071

71-
private void parse(List<String> args) {
72+
private void parse(List<String> args) {
7273
List<Object> parsedFilters = new ArrayList<Object>();
7374
while (!args.isEmpty()) {
7475
String arg = args.remove(0);

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

+15-30
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package cucumber.runtime;
22

3-
import net.sourceforge.cobertura.ant.Regex;
4-
53
import org.junit.Test;
64

75
import java.io.File;
@@ -67,49 +65,36 @@ public void default_strict() {
6765
}
6866

6967
@Test
70-
public void name() {
71-
String someName = "someName";
72-
RuntimeOptions options = new RuntimeOptions(new Properties(), "--name", someName);
68+
public void name_without_spaces_is_preserved() {
69+
RuntimeOptions options = new RuntimeOptions(new Properties(), "--name", "someName");
7370
Pattern actualPattern = (Pattern) options.filters.iterator().next();
74-
assertEquals(someName, actualPattern.pattern());
71+
assertEquals("someName", actualPattern.pattern());
7572
}
76-
73+
7774
@Test
78-
public void name_with_spaces() {
79-
String someName = "some Name";
80-
RuntimeOptions options = new RuntimeOptions(new Properties(), "--name", someName);
75+
public void name_with_spaces_is_preserved() {
76+
RuntimeOptions options = new RuntimeOptions(new Properties(), "--name", "some Name");
8177
Pattern actualPattern = (Pattern) options.filters.iterator().next();
82-
assertEquals(someName, actualPattern.pattern());
83-
}
84-
78+
assertEquals("some Name", actualPattern.pattern());
79+
}
80+
8581
@Test
8682
public void ensure_name_with_spaces_works_with_cucumber_options() {
87-
String someName = "some Name";
8883
Properties properties = new Properties();
89-
properties.setProperty("cucumber.options", "--name '" + someName + "'");
84+
properties.setProperty("cucumber.options", "--name 'some Name'");
9085
RuntimeOptions options = new RuntimeOptions(properties);
9186
Pattern actualPattern = (Pattern) options.filters.iterator().next();
92-
assertEquals(someName, actualPattern.pattern());
87+
assertEquals("some Name", actualPattern.pattern());
9388
}
94-
89+
9590
@Test
9691
public void ensure_multiple_cucumber_options_with_spaces_parse_correctly() {
97-
String someName = "some Name";
98-
String somePath = "some file\\path";
9992
Properties properties = new Properties();
100-
properties.setProperty("cucumber.options", "--name '" + someName + "'" + " --dotcucumber '" + somePath + "'");
93+
properties.setProperty("cucumber.options", "--name 'some Name' --dotcucumber 'some file\\path'");
10194
RuntimeOptions options = new RuntimeOptions(properties);
10295
Pattern actualPattern = (Pattern) options.filters.iterator().next();
103-
assertEquals(someName, actualPattern.pattern());
104-
assertEquals(new File(somePath), options.dotCucumber);
105-
}
106-
107-
@Test
108-
public void name_short() {
109-
String someName = "someName";
110-
RuntimeOptions options = new RuntimeOptions(new Properties(), "-n", someName);
111-
Pattern actualPattern = (Pattern) options.filters.iterator().next();
112-
assertEquals(someName, actualPattern.pattern());
96+
assertEquals("some Name", actualPattern.pattern());
97+
assertEquals(new File("some file\\path"), options.dotCucumber);
11398
}
11499

115100
@Test

0 commit comments

Comments
 (0)