Skip to content
This repository was archived by the owner on Apr 29, 2024. It is now read-only.

Commit 5e5e6e3

Browse files
authored
Merge pull request #106 from Tapad/feature/supportOutputFormattingArgs
Support being able to provide a '-o' argument with configuration parameters to the 'testExecutionArgs' plugin setting
2 parents 59067e0 + f339672 commit 5e5e6e3

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

src/main/scala/com/tapad/docker/ComposeTestRunner.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ trait ComposeTestRunner extends SettingsHelper with PrintFormatting {
1818
def binPackageTests(implicit state: State): Unit = {
1919
val extracted = Project.extract(state)
2020
state.globalLogging.full.info(s"Compiling and Packaging test cases using ${testCasesPackageTask.key.label} ...")
21-
extracted.runTask(testCasesPackageTask, state)
21+
try {
22+
extracted.runTask(testCasesPackageTask, state)
23+
} catch {
24+
case e: Exception =>
25+
throw TestCodeCompilationException(e.getMessage)
26+
}
2227
}
2328

2429
/**

src/main/scala/com/tapad/docker/DockerComposePlugin.scala

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ import scala.util.Try
1717
*/
1818
case class ComposeFileFormatException(message: String) extends Exception(message)
1919

20+
/**
21+
* The exception type to be thrown when there is an issue compiling the test case code
22+
*
23+
* @param message The error message to be displayed on the console
24+
*/
25+
case class TestCodeCompilationException(message: String) extends Exception(message)
26+
2027
/**
2128
* Defines an internal to external port mapping for a Docker Compose service port
2229
*
@@ -421,13 +428,17 @@ class DockerComposePluginLocal extends AutoPlugin with ComposeFile with DockerCo
421428
val requiresShutdown = getMatchingRunningInstance(newState, args).isEmpty
422429
val (preTestState, instance) = getTestPassInstance(newState, args)
423430

424-
val finalState = if (getSetting(testPassUseCucumber))
425-
runTestPassCucumber(preTestState, args, instance)
426-
else if (getSetting(testPassUseSpecs2)) {
427-
runTestPassSpecs2(preTestState, args, instance)
428-
} else {
429-
runTestPass(preTestState, args, instance)
430-
}
431+
//Ensure that if an exception is thrown when building the test code or during the test pass that
432+
//the instance that was started is cleaned up
433+
val finalState = Try {
434+
if (getSetting(testPassUseCucumber))
435+
runTestPassCucumber(preTestState, args, instance)
436+
else if (getSetting(testPassUseSpecs2)) {
437+
runTestPassSpecs2(preTestState, args, instance)
438+
} else {
439+
runTestPass(preTestState, args, instance)
440+
}
441+
}.getOrElse(preTestState)
431442

432443
if (requiresShutdown)
433444
stopDockerCompose(finalState, Seq(instance.get.instanceName))

src/main/scala/com/tapad/docker/ExecuteInput.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,24 @@ object ExecuteInput {
5050
val ScalaTest: PartialFunction[ExecuteInput, TestRunnerCommand] = {
5151
case input: ExecuteInput if input.matches(".*org.scalatest.*") =>
5252

53+
val outputArg = "-o"
5354
val testTags = (input.runner.getArgValue(input.runner.testTagOverride, input.args) match {
5455
case Some(tag) => tag
5556
case None => input.runner.getSetting(testTagsToExecute)(input.state)
5657
}).split(',').filter(_.nonEmpty).map(tag => s"-n $tag").mkString(" ")
5758

5859
val noColorOption = if (input.suppressColor) "W" else ""
5960

61+
//If testArgs contains '-o' values then parse them out to combine with the existing '-o' setting
62+
val (testArgsOutput, testArgs) = input.testArgs.partition(_.startsWith(outputArg))
63+
val outputFormattingArgs = testArgsOutput.map(_.replace(outputArg, "")).headOption.getOrElse("")
64+
6065
val jarName = input.runner.getSetting(testCasesJar)(input.state)
6166

6267
val testRunnerCommand: Seq[String] = (Seq("java", input.debugSettings) ++
6368
input.testParamsList ++
64-
Seq("-cp", input.testDependencyClasspath, "org.scalatest.tools.Runner", s"-o$noColorOption") ++
65-
input.testArgs ++
69+
Seq("-cp", input.testDependencyClasspath, "org.scalatest.tools.Runner", s"$outputArg$noColorOption$outputFormattingArgs") ++
70+
testArgs ++
6671
Seq("-R", s"${jarName.replace(" ", "\\ ")}") ++
6772
testTags.split(" ").toSeq ++
6873
input.testParamsList).filter(_.nonEmpty)

0 commit comments

Comments
 (0)