Added code to call Runner's done() method in both InProcess and SubProcess cases.

This commit is contained in:
cheeseng 2013-04-04 21:43:02 +08:00
parent 244e65cd79
commit f38a244d0f
7 changed files with 92 additions and 2 deletions

View File

@ -15,7 +15,7 @@ package sbt
import complete._
import std.TaskExtra._
import inc.{FileValueCache, Locate}
import testing.{Framework, AnnotatedFingerprint, SubclassFingerprint}
import testing.{Framework, Runner, AnnotatedFingerprint, SubclassFingerprint}
import sys.error
import scala.xml.NodeSeq
@ -478,7 +478,11 @@ object Defaults extends BuildCommon
Tests(frameworks, loader, runners, tests, config, s.log)
}
}
Tests.foldTasks(groupTasks, config.parallel)
val output = Tests.foldTasks(groupTasks, config.parallel)
runners foreach { case (tf, r) =>
r.done()
}
output
}
def selectedFilter(args: Seq[String]): Seq[String => Boolean] =

View File

@ -0,0 +1,5 @@
scalaVersion := "2.10.1"
libraryDependencies += "org.scalatest" %% "scalatest" % "2.0.M6-SNAP15"
testOptions in Test += Tests.Argument("-r", "custom.CustomReporter")

View File

@ -0,0 +1,37 @@
package custom
import java.io._
import org.scalatest._
import events._
class CustomReporter extends ResourcefulReporter {
private def writeFile(filePath: String, content: String) {
val file = new File(filePath)
val writer =
if (!file.exists)
new FileWriter(new File(filePath))
else
new FileWriter(new File(filePath + "-2"))
writer.write(content)
writer.flush()
writer.close()
}
def apply(event: Event) {
event match {
case runCompleted: RunCompleted => writeFile("target/RunCompleted", "RunCompleted")
case _ =>
}
}
def dispose() {
val file = new File("target/dispose")
val filePath =
if (file.exists)
"target/dispose2"
else
"target/dispose"
writeFile(filePath, "dispose")
}
}

View File

@ -0,0 +1,12 @@
package com.test
import org.scalatest.Spec
class TestSpec extends Spec {
def `TestSpec-test-1 ` {}
def `TestSpec-test-2 ` {}
def `TestSpec-test-3 ` {}
}

View File

@ -0,0 +1,12 @@
package com.test
import org.scalatest.Spec
class TestSpec2 extends Spec {
def `TestSpec2-test-1 ` {}
def `TestSpec2-test-2 ` {}
def `TestSpec2-test-3 ` {}
}

View File

@ -0,0 +1,19 @@
#Test the framework will call Runner.done once.
#Because ScalaTest's runner will report RunCompleted when the run completed, a CustomReporter is
#used to report expected ScalaTest's RunCompleted event by writing out to target/, it is then
#used to check for their existence, and if the expected event is fired > 1 (which is unexpected),
#a xxxx-2 file will be written, thus here we also check for 'absent' of such file.
#ResourcefulReporter's dispose method will be called in Runner.done also, and it should be called
#once only.
> clean
> test
$ exists target/RunCompleted
$ absent target/RunCompleted-2
$ exists target/dispose
$ absent target/dispose2

View File

@ -212,6 +212,7 @@ public class ForkMain {
final Runner runner = framework.runner(frameworkArgs, remoteFrameworkArgs, getClass().getClassLoader());
for (ForkTestDefinition test : filteredTests)
runTestSafe(test, runner, loggers, os);
runner.done();
}
write(os, ForkTags.Done);
is.readObject();