]>
Dogcows Code - chaz/sbt-tap/blob - src/main/scala/SbtTapReporting.scala
20d8b7c9d1cedb479bd825fd5e9a4cb0652ae65a
2 import org
.scalatools
.testing
.{Event
=> TEvent
, Result
=> TResult
}
4 import java
.util
.concurrent
.atomic
.AtomicInteger
5 import java
.io
.{File
, FileWriter
}
7 object SbtTapReporting
extends Plugin
{
8 lazy val tapListener
= new SbtTapListener
12 * Listens to sbt test listener events and writes them to a tap compatible file. Results for all groups
13 * go to a single file although it might be desirable to generate one tap file per group.
15 * sbt runs tests in parallel and the protocol does not seem to provide a way to match a group to a test event. It
16 * does look line one thread calls startGroup/testEvent/endGroup sequentially and using thread local to keep
17 * the current active group might be one way to go.
19 class SbtTapListener
extends TestsListener
{
20 var testId
= new AtomicInteger(0)
21 var fileWriter
: FileWriter
= _
24 println("doInit called in sbt tap plugin")
25 new File("test-results").mkdirs()
27 fileWriter
= new FileWriter("test-results/test.tap")
30 def startGroup(name
: String
) {}
32 def testEvent(event
: TestEvent
) {
33 event
.detail
.foreach
{ e
: TEvent
=>
35 case TResult
.Success
=> writeTapFields("ok", testId
.incrementAndGet(), "-", e
.testName())
36 case TResult
.Error
| TResult
.Failure
=>
37 writeTapFields("not ok", testId
.incrementAndGet(), "-", e
.testName())
38 // TODO: for exceptions, write stack trace to tap file.
39 case TResult
.Skipped
=>
40 // it doesn't look like this framework distinguishes between pending and ignored.
41 writeTapFields("ok", testId
.incrementAndGet(), "#", "skip", e
.testName())
46 override def doComplete(finalResult
: TestResult
.Value
) {
47 writeTapFields("1.." + testId
.get
)
51 private def writeTapFields(s
: Any
*) { fileWriter
.write(s
.mkString("", " ", "\n")) }
53 def endGroup(name
: String
, t
: Throwable
) { }
55 def endGroup(name
: String
, result
: TestResult
.Value
) { }
This page took 0.038387 seconds and 3 git commands to generate.