Skip to content

Commit 84c70da

Browse files
author
Klaus
committed
throw exception when unsupported options are passed
when options starting with a dash are passed which aren't handled specifically, the usages are printed to system.out and an exception is thrown Issue cucumber#463
1 parent c906b4e commit 84c70da

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private void parse(List<String> args) {
7575
String arg = args.remove(0).trim();
7676

7777
if (arg.equals("--help") || arg.equals("-h")) {
78-
System.out.println(USAGE);
78+
printUsage();
7979
System.exit(0);
8080
} else if (arg.equals("--version") || arg.equals("-v")) {
8181
System.out.println(VERSION);
@@ -100,6 +100,9 @@ private void parse(List<String> args) {
100100
String nextArg = args.remove(0);
101101
Pattern patternFilter = Pattern.compile(nextArg);
102102
parsedFilters.add(patternFilter);
103+
} else if (arg.startsWith("-")) {
104+
printUsage();
105+
throw new CucumberException("Unknown option: " + arg);
103106
} else {
104107
PathWithLines pathWithLines = new PathWithLines(arg);
105108
featurePaths.add(pathWithLines.path);
@@ -112,6 +115,11 @@ private void parse(List<String> args) {
112115
}
113116
}
114117

118+
private void printUsage()
119+
{
120+
System.out.println(USAGE);
121+
}
122+
115123
public List<CucumberFeature> cucumberFeatures(ResourceLoader resourceLoader) {
116124
return load(resourceLoader, featurePaths, filters);
117125
}

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

+12
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import static org.junit.Assert.assertEquals;
1212
import static org.junit.Assert.assertFalse;
1313
import static org.junit.Assert.assertTrue;
14+
import static org.junit.Assert.fail;
1415

1516
public class RuntimeOptionsTest {
1617
@Test
@@ -153,4 +154,15 @@ public void allows_removal_of_strict_in_cucumber_options_property() {
153154
RuntimeOptions runtimeOptions = new RuntimeOptions(properties, "--strict");
154155
assertFalse(runtimeOptions.strict);
155156
}
157+
158+
@Test
159+
public void fail_on_unsupported_options() {
160+
try {
161+
new RuntimeOptions(new Properties(), "-concreteUnsupportedOption", "somewhere", "somewhere_else");
162+
fail();
163+
} catch (CucumberException e) {
164+
assertEquals("Unknown option: -concreteUnsupportedOption", e.getMessage());
165+
}
166+
}
167+
156168
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ public void strict_with_errors() {
164164
}
165165

166166
private Runtime createStrictRuntime() {
167-
return createRuntime("-g anything", "--strict");
167+
return createRuntime("-g", "anything", "--strict");
168168
}
169169

170170
private Runtime createNonStrictRuntime() {
171-
return createRuntime("-g anything");
171+
return createRuntime("-g", "anything");
172172
}
173173

174174
private Runtime createRuntime(String... runtimeArgs) {

0 commit comments

Comments
 (0)