Permalink
Browse files

WIP for #160

  • Loading branch information...
1 parent 8633ed0 commit b4ad2d29f9da77a2dd2afa2672d6211fd64af318 @aslakhellesoy aslakhellesoy committed Feb 23, 2012
View
@@ -22,6 +22,10 @@
<groupId>info.cukes</groupId>
<artifactId>cucumber-html</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.beust</groupId>
+ <artifactId>jcommander</artifactId>
+ </dependency>
<!-- These dependencies are packaged to prevent conflicts with users' own code -->
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
@@ -0,0 +1,54 @@
+package cucumber.runtime;
+
+import com.beust.jcommander.IStringConverter;
+import com.beust.jcommander.IStringConverterFactory;
+import com.beust.jcommander.JCommander;
+import com.beust.jcommander.Parameter;
+import cucumber.formatter.HTMLFormatter;
+import gherkin.formatter.Formatter;
+
+import java.io.File;
+import java.util.List;
+
+public class RuntimeOptions {
+ @Parameter(names = {"-g", "--glue"}, description = "Where cucumber looks for step definitions and hooks.", required = true)
+ public String glue;
+
+ @Parameter(names = {"--dotcucumber"}, description = "Where to output .cucumber files (for code completion).")
+ public File dotCucumber;
+
+ @Parameter(names = {"--dry-run"}, description = "Don't run anything, just format the features.")
+ public File dryRun;
+
+ @Parameter(names = {"--tags"}, description = "Only execute scenarios matching TAG_EXPRESSION.")
+ public List<String> tags;
+
+ @Parameter(names = {"--strict"}, description = "Fail if there are any undefined or pending steps.")
+ public boolean strict;
+
+ @Parameter(names = {"--format"}, description = "Formatter to use.")
+ public List<Formatter> formatters;
+
+
+ public RuntimeOptions(String... args) {
+ JCommander cmd = new JCommander(this);
+ cmd.addConverterFactory(new FormatterFactory());
+ cmd.setProgramName("cucumber");
+ cmd.parse(args);
+ }
+
+ public static class FormatterFactory implements IStringConverterFactory {
+ @Override
+ public Class<? extends IStringConverter<?>> getConverter(Class forType) {
+ if (forType.equals(Formatter.class)) return FormatterConverter.class;
+ else return null;
+ }
+ }
+
+ public static class FormatterConverter implements IStringConverter<Formatter> {
+ @Override
+ public Formatter convert(String value) {
+ return new HTMLFormatter(new File("target"));
+ }
+ }
+}
@@ -0,0 +1,29 @@
+package cucumber.runtime;
+
+import com.beust.jcommander.JCommander;
+import cucumber.formatter.HTMLFormatter;
+import org.junit.Test;
+
+import java.io.File;
+
+import static junit.framework.Assert.assertEquals;
+
+public class RuntimeOptionsTest {
+ @Test
+ public void assigns_glue() {
+ RuntimeOptions options = new RuntimeOptions("--glue", "somewhere");
+ assertEquals("somewhere", options.glue);
+ }
+
+ @Test
+ public void assigns_dotcucumber() {
+ RuntimeOptions options = new RuntimeOptions("--dotcucumber", "somewhere", "--glue", "somewhere");
+ assertEquals(new File("somewhere"), options.dotCucumber);
+ }
+
+ @Test
+ public void creates_formatter() {
+ RuntimeOptions options = new RuntimeOptions("--format", "html:some/dir", "--glue", "somewhere");
+ assertEquals(HTMLFormatter.class, options.formatters.get(0).getClass());
+ }
+}
@@ -1,9 +1,7 @@
package cucumber.examples.scalacalculator
import org.junit.runner.RunWith
-import cucumber.junit.Cucumber.Options
-import cucumber.junit.{Options, Cucumber}
+import cucumber.junit.Cucumber
@RunWith(classOf[Cucumber])
-@Options("basic_arithmetic.feature")
class RunCukesTest
View
11 pom.xml
@@ -1,4 +1,5 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm</artifactId>
@@ -80,6 +81,11 @@
<version>${gherkin.version}</version>
</dependency>
<dependency>
+ <groupId>com.beust</groupId>
+ <artifactId>jcommander</artifactId>
+ <version>1.23</version>
+ </dependency>
+ <dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy.version}</version>
@@ -341,7 +347,8 @@
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>full</shadedClassifierName>
<transformers>
- <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+ <transformer
+ implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>cucumber.cli.Main</mainClass>
</transformer>
</transformers>

0 comments on commit b4ad2d2

Please sign in to comment.