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

Fix for #20 - Add Support for CLI options #21

Closed
wants to merge 3 commits into from
Closed
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
34 changes: 29 additions & 5 deletions plugin/src/main/scala/templemore/sbt/cucumber/Integration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import templemore.sbt.util._
* cucumber as both a forked JVM and within the current JVM process.
*
* @author Chris Turner
* @author RandomCoder
*/
trait Integration {

Expand All @@ -32,20 +33,41 @@ trait Integration {
}
}

/*
* The options that are supported by the plugin.
* This excludes options that are set in other places such as formatting
* and dotcucumber etc.
*
* This is essentially a list of the parameter-less options supported by the
* `cucumber-jvm` `cucumber.runtime.RuntimeOptions` class
*
* The `--no-xxx` version of the options are not included as they are not enabled
* by default and are therefore not really necessary.
*/
private val supportedOptions = Seq("-d",
"--dry-run",
"-s",
"--strict",
"-m",
"--monochrome")


private def runCucumber(args: Seq[String],
jvmSettings: JvmSettings,
options: Options,
output: Output,
log: Logger) = {
def tagsFromArgs = args.filter(isATag).toList
def namesFromArgs = args.filter(isNotATag).toList
def optsFromArgs = args.filter(isAnOption).toList
def namesFromArgs = args.filter(isAName).toList

def isATag(arg: String) = arg.startsWith("@") || arg.startsWith("~")
def isNotATag(arg: String) = !isATag(arg)
def isAnOption(arg: String) = supportedOptions.contains(arg)
def isATag(arg: String) = arg.startsWith("@") || arg.startsWith("~@")
def isAName(arg:String) = !isATag(arg) && !isAnOption(arg)

log.info("Running cucumber...")
options.beforeFunc()
val result = launchCucumberInSeparateJvm(jvmSettings, options, output, tagsFromArgs, namesFromArgs)
val result = launchCucumberInSeparateJvm(jvmSettings, options, output, tagsFromArgs, namesFromArgs, optsFromArgs)
options.afterFunc()
result
}
Expand All @@ -54,14 +76,16 @@ trait Integration {
options: Options,
output: Output,
tags: List[String],
names: List[String]): Int = {
names: List[String],
cucumberOptions: List[String]): Int = {
def makeOptionsList(options: List[String], flag: String) = options flatMap(List(flag, _))

val cucumberParams = ("--glue" :: options.basePackage :: Nil) ++
options.extraOptions ++
output.options ++
makeOptionsList(tags, "--tags") ++
makeOptionsList(names, "--name") ++
cucumberOptions ++
(options.featuresLocation :: Nil)
JvmLauncher(jvmSettings).launch(cucumberParams)
}
Expand Down
20 changes: 14 additions & 6 deletions project/Build.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import sbt._
import Keys._

import Versions._

object Settings {
val buildOrganization = "templemore"
val buildScalaVersion = "2.9.2"
val buildScalaVersion = scala2_9
val buildVersion = "0.7.2"

val buildSettings = Defaults.defaultSettings ++
Expand All @@ -16,9 +18,6 @@ object Settings {

object Dependencies {

private val CucumberVersionForScala2_9 = "1.0.9"
private val CucumberVersionForScala2_10 = "1.1.1"

def cucumberScala(scalaVersion: String) = {
def cucumberVersion = if ( scalaVersion.startsWith("2.10") ) CucumberVersionForScala2_10 else CucumberVersionForScala2_9
"info.cukes" % "cucumber-scala" % cucumberVersion % "compile"
Expand All @@ -32,18 +31,27 @@ object Build extends Build {
import Dependencies._
import Settings._

private val crossVersions = Seq(scala2_9, scala2_10)

lazy val parentProject = Project("sbt-cucumber-parent", file ("."),
settings = buildSettings ++
Seq(crossScalaVersions := Seq("2.9.2", "2.10.0-RC2"))) aggregate (pluginProject, integrationProject)
Seq(crossScalaVersions := crossVersions)) aggregate (pluginProject, integrationProject)

lazy val pluginProject = Project("sbt-cucumber-plugin", file ("plugin"),
settings = buildSettings ++
Seq(sbtPlugin := true))

lazy val integrationProject = Project ("sbt-cucumber-integration", file ("integration"),
settings = buildSettings ++
Seq(crossScalaVersions := Seq("2.9.2", "2.10.0-RC2"),
Seq(crossScalaVersions := crossVersions,
libraryDependencies <+= scalaVersion { sv => cucumberScala(sv) },
libraryDependencies += testInterface))
}


object Versions {
val scala2_9 = "2.9.2"
val scala2_10 = "2.10.0"
val CucumberVersionForScala2_9 = "1.0.9"
val CucumberVersionForScala2_10 = "1.1.1"
}