Created
August 7, 2013 19:58
-
-
Save jdolson/6177988 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sbt._ | |
import sbt.testing.Event | |
import scala.collection.{concurrent, mutable} | |
class ThreadSafeTestsListener extends TestReportListener { | |
val groups = concurrent.TrieMap.empty[String, TestGroup] | |
class TestGroup(val name: String) { | |
val events = new mutable.ArrayBuffer[Event] // does this need to be an ArrayBlockingQueue? | |
} | |
def startGroup(name: String) { | |
groups.putIfAbsent(name, new TestGroup(name)) | |
} | |
def testEvent(event: TestEvent) { | |
// if all events correspond to one group and we had `name` on event we could do | |
// groups(event.name) ++= event.detail | |
// but we don't, so we handle each individual detail item individually | |
for (e <- event.detail) { | |
val name = e.fullyQualifiedName // does this always corresponds to the group name? | |
groups(name).events += e | |
} | |
} | |
def endGroup(name: String, result: TestResult.Value) { | |
groups.remove(name) match { | |
case Some(group) => // do something with group.events | |
case None => | |
} | |
} | |
def endGroup(name: String, t: Throwable) { | |
groups.remove(name) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment