X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fscala%2FSbtTapReporting.scala;h=9345066996c621c06df72c08b10e2625c85583f4;hb=7b47de44e98f157ae5edae5ceafa5249cebe3cfd;hp=2524bda33ddaa57f11667d840c5f497120fbc4dd;hpb=edbf311f88823359d167c75600086d9f93dc63ed;p=chaz%2Fsbt-tap diff --git a/src/main/scala/SbtTapReporting.scala b/src/main/scala/SbtTapReporting.scala index 2524bda..9345066 100644 --- a/src/main/scala/SbtTapReporting.scala +++ b/src/main/scala/SbtTapReporting.scala @@ -1,16 +1,11 @@ -package sbttap - +import java.io.{PrintWriter, StringWriter, File, FileWriter} import sbt._ import org.scalatools.testing.{Event => TEvent, Result => TResult} -import Keys._ import java.util.concurrent.atomic.AtomicInteger -import java.io.{File, FileWriter} object SbtTapReporting extends Plugin { - override def settings = Seq( - testListeners ++= Seq(new SbtTapListener) - ) + def apply() = new SbtTapListener } /** @@ -39,10 +34,13 @@ class SbtTapListener extends TestsListener { case TResult.Success => writeTapFields("ok", testId.incrementAndGet(), "-", e.testName()) case TResult.Error | TResult.Failure => writeTapFields("not ok", testId.incrementAndGet(), "-", e.testName()) - // TODO: for exceptions, write stack trace to tap file. + // According to the TAP spec, as long as there is any kind of whitespace, this output should belong to the + // the test that failed and it should get displayed in the UI. + // TODO:It would be nice if we could report the exact line in the test where this happened. + writeTapFields(" ", stackTraceForError(e.error())) case TResult.Skipped => // it doesn't look like this framework distinguishes between pending and ignored. - writeTapFields("ok", testId.incrementAndGet(), "#", "skip", e.testName()) + writeTapFields("ok", testId.incrementAndGet(), e.testName(), "#", "skip", e.testName()) } } } @@ -54,6 +52,12 @@ class SbtTapListener extends TestsListener { private def writeTapFields(s: Any*) { fileWriter.write(s.mkString("", " ", "\n")) } + private def stackTraceForError(t: Throwable): String = { + val sw = new StringWriter() + val printWriter = new PrintWriter(sw) + t.printStackTrace(printWriter) + sw.toString + } def endGroup(name: String, t: Throwable) { } def endGroup(name: String, result: TestResult.Value) { }