From 37a33da19bc4034f15db3d9468f74293902647ca Mon Sep 17 00:00:00 2001 From: Manish Khettry Date: Wed, 25 Apr 2012 17:39:53 -0700 Subject: [PATCH] print stack trace --- src/main/scala/SbtTapReporting.scala | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/scala/SbtTapReporting.scala b/src/main/scala/SbtTapReporting.scala index c6e0068..45510ac 100644 --- a/src/main/scala/SbtTapReporting.scala +++ b/src/main/scala/SbtTapReporting.scala @@ -1,8 +1,8 @@ +import java.io.{PrintWriter, StringWriter, File, FileWriter} import sbt._ import org.scalatools.testing.{Event => TEvent, Result => TResult} import java.util.concurrent.atomic.AtomicInteger -import java.io.{File, FileWriter} object SbtTapReporting extends Plugin { lazy val tapListener = new SbtTapListener @@ -34,10 +34,10 @@ 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. + 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") } } } @@ -49,6 +49,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) { } -- 2.45.2